repo_name
stringlengths 5
122
| path
stringlengths 3
232
| text
stringlengths 6
1.05M
|
|---|---|---|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Plugin/Transaction/Payload/OutputPayload/PayloadDefault.h
|
<gh_stars>10-100
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_OUTPUT_PAYLOADDEFAULT_H
#define __ELASTOS_SDK_OUTPUT_PAYLOADDEFAULT_H
#include <Plugin/Transaction/Payload/OutputPayload/IOutputPayload.h>
namespace Elastos {
namespace ElaWallet {
class PayloadDefault : public IOutputPayload {
public:
PayloadDefault();
PayloadDefault(const PayloadDefault &payload);
~PayloadDefault();
virtual size_t EstimateSize() const;
virtual void Serialize(ByteStream &ostream) const;
virtual bool Deserialize(const ByteStream &istream);
virtual nlohmann::json ToJson() const;
virtual void FromJson(const nlohmann::json &j);
virtual IOutputPayload &operator=(const IOutputPayload &payload);
virtual PayloadDefault &operator=(const PayloadDefault &payload);
};
}
}
#endif //__ELASTOS_SDK_OUTPUT_PayloadDefault_H
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
Interface/IMasterWallet.h
|
/*
* Copyright (c) 2019 Elastos Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __ELASTOS_SDK_IMASTERWALLET_H__
#define __ELASTOS_SDK_IMASTERWALLET_H__
#include "ISubWallet.h"
namespace Elastos {
namespace ElaWallet {
class IMasterWallet {
public:
/**
* Virtual destructor.
*/
virtual ~IMasterWallet() noexcept {}
/**
* Get the master wallet id.
* @return master wallet id.
*/
virtual std::string GetID() const = 0;
/**
* Get basic info of master wallet
* @return basic information. Such as:
* {"M":1,"N":1,"Readonly":false,"SingleAddress":false,"Type":"Standard", "HasPassPhrase": false}
*/
virtual nlohmann::json GetBasicInfo() const = 0;
/**
* Get wallet existing sub wallets.
* @return existing sub wallets by array.
*/
virtual std::vector<ISubWallet *> GetAllSubWallets() const = 0;
/**
* Get a sub wallet of chainID.
* @param chainID unique identity of a sub wallet. Chain id should not be empty.
* @return If success will return a pointer of sub wallet interface.
*/
virtual ISubWallet *GetSubWallet(const std::string &chainID) const = 0;
/**
* Create a sub wallet of chainID.
* @param chainID unique identity of a sub wallet. Chain id should not be empty.
* @return If success will return a pointer of sub wallet interface.
*/
virtual ISubWallet *CreateSubWallet(const std::string &chainID) = 0;
/**
* Export Keystore of the current wallet in JSON format.
* @param backupPassword use to decrypt key store file. Backup password should between 8 and 128, otherwise will throw invalid argument exception.
* @param payPassword use to decrypt and generate mnemonic temporarily. Pay password should between 8 and 128, otherwise will throw invalid argument exception.
* @return If success will return key store content in json format.
*/
virtual nlohmann::json ExportKeystore(
const std::string &backupPassword,
const std::string &payPassword) const = 0;
/**
* Export mnemonic of the current wallet.
* @param payPassword use to decrypt and generate mnemonic temporarily. Pay password should between 8 and 128, otherwise will throw invalid argument exception.
* @return If success will return the mnemonic of master wallet.
*/
virtual std::string ExportMnemonic(const std::string &payPassword) const = 0;
/**
* Export wallet info except private keys.
* @return If success, readonly wallet will be returned.
*/
virtual nlohmann::json ExportReadonlyWallet() const = 0;
/**
* Export root private key of the current wallet.
* @param payPasswd use to decrypt and generate mnemonic temporarily. Pay password should between 8 and 128, otherwise will throw invalid argument exception.
* @return root private key.
*/
virtual std::string ExportPrivateKey(const std::string &payPasswd) const = 0;
/**
* Export master public key.
* @return master public key
*/
virtual std::string ExportMasterPublicKey() const = 0;
/**
* Verify private key whether same as current wallet
* @param mnemonic
* @param passphrase
* @return
*/
virtual bool VerifyPrivateKey(const std::string &mnemonic, const std::string &passphrase) const = 0;
/**
*
* @param passphrase
* @param payPasswd
* @return
*/
virtual bool VerifyPassPhrase(const std::string &passphrase, const std::string &payPasswd) const = 0;
/**
*
* @param payPasswd
* @return
*/
virtual bool VerifyPayPassword(const std::string &payPasswd) const = 0;
/**
* Destroy a sub wallet created by the master wallet.
* @param chainID chain ID of subWallet.
*/
virtual void DestroyWallet(const std::string &chainID) = 0;
/**
* Get public key info
* @return public key info
*/
virtual nlohmann::json GetPubKeyInfo() const = 0;
/**
* Verify an address which can be normal, multi-sign, cross chain, or id address.
* @param address to be verified.
* @return True if valid, otherwise return false.
*/
virtual bool IsAddressValid(const std::string &address) const = 0;
/**
* Get all chain ids of supported chains.
* @return a list of chain id.
*/
virtual std::vector<std::string> GetSupportedChains() const = 0;
/**
* Change pay password which encrypted private key and other important data in memory.
* @param oldPassword the old pay password.
* @param newPassword new pay password.
*/
virtual void ChangePassword(const std::string &oldPassword, const std::string &newPassword) = 0;
};
}
}
#endif //__ELASTOS_SDK_IMASTERWALLET_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/base/BREthereumLogic.h
|
<gh_stars>0
//
// BREthereumLogic
// breadwallet-core Ethereum
//
// Created by <NAME> on 3/22/18.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#ifndef BR_Ethereum_Logic_H
#define BR_Ethereum_Logic_H
#ifdef __cplusplus
extern "C" {
#endif
#define private_extern extern
//
// Etherum Boolean
//
typedef enum {
ETHEREUM_BOOLEAN_TRUE = 0, // INTENTIONALLY 'backwards'
ETHEREUM_BOOLEAN_FALSE = 1
} BREthereumBoolean;
#define ETHEREUM_BOOLEAN_IS_TRUE(x) ((x) == ETHEREUM_BOOLEAN_TRUE)
#define ETHEREUM_BOOLEAN_IS_FALSE(x) ((x) == ETHEREUM_BOOLEAN_FALSE)
#define AS_ETHEREUM_BOOLEAN(x) ((x) ? ETHEREUM_BOOLEAN_TRUE : ETHEREUM_BOOLEAN_FALSE)
//
// Ethereum Comparison
//
typedef enum {
ETHEREUM_COMPARISON_LT = -1,
ETHEREUM_COMPARISON_EQ = 0,
ETHEREUM_COMPARISON_GT = +1
} BREthereumComparison;
#ifdef __cplusplus
}
#endif
#endif /* BR_Ethereum_Logic_H */
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/les/BREthereumLESBase.h
|
<reponame>fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
//
// BREthereumLESBase.h
// Core
//
// Created by <NAME> on 9/1/18.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#ifndef BR_Ethereum_LES_Base_H
#define BR_Ethereum_LES_Base_H
#include "support/BRSet.h"
#include "support/BRArray.h"
#include "ethereum/util/BRUtil.h"
#include "ethereum/rlp/BRRlp.h"
#include "ethereum/base/BREthereumHash.h"
#include "ethereum/blockchain/BREthereumNetwork.h"
#define DEFAULT_UDPPORT (30303)
#define DEFAULT_TCPPORT (30303)
#define LES_LOCAL_ENDPOINT_ADDRESS "1.1.1.1"
#define LES_LOCAL_ENDPOINT_TCP_PORT DEFAULT_TCPPORT
#define LES_LOCAL_ENDPOINT_UDP_PORT DEFAULT_UDPPORT
#define LES_LOCAL_ENDPOINT_NAME "BRD Light Client"
#define LES_LOG_TOPIC "LES"
/** */
//#define LES_SUPPORT_PARITY
#define LES_SUPPORT_PARITY_VERSION (1)
/** */
#define LES_SUPPORT_GETH
#define LES_SUPPORT_GETH_VERSION (2)
#define LES_SUPPORT_GETH_ANNOUNCE_TYPE (1)
/**
* We can optionally only bootstrap from a BRD server. Setting this overrides the subsequent
* LES_BOOTSTRAP_LCL_ONLY
*/
// #define LES_BOOTSTRAP_BRD_ONLY
/**
* For debugging only, we can optionally only bootstrap from a LCL (local) server.
*/
#if defined (LES_BOOTSTRAP_BRD_ONLY) || defined (NDEBUG) || !defined (DEBUG)
#undef LES_BOOTSTRAP_LCL_ONLY
#endif
//#define LES_BOOTSTRAP_LCL_ONLY
/**
* For debugging only, we can optionally disable P2P Node Discovery. This is very useful for
* performance and memory allocation/leak analysis
*/
#if defined (NDEBUG) || !defined (DEBUG)
#undef LES_DISABLE_DISCOVERY
#endif
//#define LES_DISABLE_DISCOVERY
/**
* If we attempt to open a socket to a node endpoint and the socket reports EINPROGRESS, we'll
* select() on the socket with this timeout. See CORE-265. This occurs on the LES thread and
* is a blocking operation - blocking *all* other nodes. We should consider attempting to resolve
* an EINPROGRESS by introducing another 'connecting' state (between OPEN and AUTH). That new
* state will wait on the 'write file descriptor' and then do `getsockopt()` - if success then
* move to AUTH otherwise error.
*
* But, the above is too onerous at this time. We can wait; nobody is going any where.
*/
#define NODE_ENDPOINT_OPEN_SOCKET_TIMEOUT 3.0
/**
* The Supported P2P version - this applies to both DIS and P2P messaging. There is a V5
* discovery protocol (at least in Geth) that is defined so as to facilitate discovery of LES
* nodes... fact is, if we need to explore one node to find a LES node, then we might as well
* explore N nodes. And, if Geth wants to faclitate LES nodes, then just turn on LES by default.
*
* https://github.com/ethereum/devp2p/blob/master/discv4.md
*/
#define P2P_MESSAGE_VERSION 0x04
// The number of nodes that should be maintained as 'active' (aka 'connected'). Once connected we
// will get announcements of new blocks. When a transaction is submitted we'll submit it to *all*
// active nodes. We will need multiple active nodes for submissions as we *routinely* see nodes
// simply dropping submission outright, quietly.
#define LES_ACTIVE_NODE_COUNT 1
// When discovering nodes (on UDP) don't allow more then LES_ACTIVE_NODE_UDP_LIMIT nodes to be
// actively discovering at once.
#define LES_ACTIVE_NODE_UDP_LIMIT 1
// The number of nodes that should be available. We'll discover nodes until we reach this count.
// Note that this doesn mean that the nodes are LESv2 or PIPv1 nodes - they are just nodes. As
// we explore individual nodes they may become unavailable and we'll need to discover more.
#define LES_AVAILABLE_NODES_COUNT (10)
// For a request with a nodeIndex that is not LES_PREFERRED_NODE_INDEX, the intention is to send
// the same message multiple times. If the message was to be sent to 3 nodes, but only two are
// connected, how many times should the message be sent and to what nodes? If the following,
// LES_WRAP_SEND_WHEN_MULTIPLE_INDEX, is '1' when we'll send 3 times, including multiple times. If
// the following is '0' then we'll multiple times up to the number of connected nodes.
//
// TODO: Unused
#define LES_WRAP_SEND_WHEN_MULTIPLE_INDEX 1
#ifdef __cplusplus
extern "C" {
#endif
// BREthereumMessageCoder - when RLP encoding and decoding messages, we need both the
// RLP Coder, the Network and a LES message offset. The network is required for decoding
// transactions - where the signature encodes the network's chain id. The LES message offset
// is required to offset a LES message id (away from the P2P id space).
//
// We could have considered modifying BRRlpCoder to include the network - however, the RLP
// module *absolutely does not* depend on anything... So we'll use this 'MessageCoder' abstraction
// to bundle all the LES specific needs.
//
typedef struct {
BRRlpCoder rlp;
BREthereumNetwork network;
// The offset for LES messages. This is determined by 'negotiating' subprotocols
// https://github.com/ethereum/wiki/wiki/ÐΞVp2p-Wire-Protocol
//
// "ÐΞVp2p is designed to support arbitrary sub-protocols (aka capabilities) over the basic
// wire protocol. Each sub-protocol is given as much of the message-ID space as it needs (all
// such protocols must statically specify how many message IDs they require). On connection and
// reception of the Hello message, both peers have equivalent information about what
// subprotocols they share (including versions) and are able to form consensus over the
// composition of message ID space.
//
// "Message IDs are assumed to be compact from ID 0x10 onwards (0x00-0x10 is reserved for
// ÐΞVp2p messages) and given to each shared (equal-version, equal name) sub-protocol in
// alphabetic order. Sub-protocols that are not shared are ignored. If multiple versions are
// shared of the same (equal name) sub-protocol, the numerically highest wins, others are
// ignored."
//
// Generally, we have one protocol specified
uint64_t messageIdOffset;
} BREthereumMessageCoder;
#ifdef __cplusplus
}
#endif
#endif /* BR_Ethereum_LES_Base_H */
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/blockchain/BREthereumNetwork.c
|
<filename>ThirdParty/breadwallet-core/ethereum/blockchain/BREthereumNetwork.c
//
// BREthereumNetwork
// breadwallet-core Ethereum
//
// Created by <NAME> on 3/13/18.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#include <stdlib.h>
#include "BREthereumNetwork.h"
#define NUMBER_OF_SEEDS_LIMIT (5)
#define NUMBER_OF_ENODES_LIMIT (10)
static void
networkInitilizeAllIfAppropriate (void);
//
// Network
//
struct BREthereumNetworkRecord {
const char *name;
int chainId;
int networkId;
BREthereumHash genesisBlockHeaderHash;
BREthereumHash trustedCheckpointBlockHeaderHash;
const char *seeds[NUMBER_OF_SEEDS_LIMIT + 1];
const char *enodesBRD[NUMBER_OF_ENODES_LIMIT + 1];
const char *enodesCOM[NUMBER_OF_ENODES_LIMIT + 1];
const char *enodesLCLParity[4];
const char *enodesLCLGeth[4];
};
extern BREthereumChainId
networkGetChainId (BREthereumNetwork network) {
networkInitilizeAllIfAppropriate();
return network->chainId;
}
extern BREthereumNetworkId
networkGetNetworkId (BREthereumNetwork network) {
networkInitilizeAllIfAppropriate();
return network->networkId;
}
extern BREthereumHash
networkGetGenesisBlockHeaderHash (BREthereumNetwork network) {
networkInitilizeAllIfAppropriate();
return network->genesisBlockHeaderHash;
}
extern BREthereumHash
networkGetTrustedCheckpointBlockHeaderHash (BREthereumNetwork network) {
networkInitilizeAllIfAppropriate();
return network->trustedCheckpointBlockHeaderHash;
}
extern const char *
networkGetName (BREthereumNetwork network) {
return network->name;
}
extern const char**
networkGetSeeds (BREthereumNetwork network) {
return network->seeds;
}
extern size_t
networkGetSeedsCount (BREthereumNetwork network) {
size_t i = 0;
while (NULL != network->seeds[i]) i++;
return i;
}
extern const char**
networkGetEnodesBRD (BREthereumNetwork network) {
return network->enodesBRD;
}
extern const char**
networkGetEnodesCommunity (BREthereumNetwork network) {
return network->enodesCOM;
}
extern const char**
networkGetEnodesLocal (BREthereumNetwork network, int parity) {
return parity ? network->enodesLCLParity : network->enodesLCLGeth;
}
/// MARK: - Static Network Definitions
//
// Mainnet
//
static struct BREthereumNetworkRecord ethereumMainnetRecord = {
"Mainnet",
0,
1,
EMPTY_HASH_INIT,
EMPTY_HASH_INIT,
// Seeds
{ //"seed.mainnet.eth.brd.breadwallet.com",
//"seed.mainnet.eth.community.breadwallet.com",
NULL },
// Enodes
// BRD
{ "enode://dee112e94b17b3b49366e5dec78d7e8a1ee342ff363b490819d40a55482046d333b2bd51b3d1ce250078c5315bf302758d13f63ac94fd8e43f6e54be8412c316@192.168.127.12:20630",
"enode://152fae4134f4db49d24905762ade694fc86e0a24124c0927c9c1cbc816bb9929e790d4fba236c7a55c9d9817df72c1d23353c2dccc3796bd397d72320a722ef1@172.16.58.3:20630",
"enode://dbfdb62b5cf4cb5a12ee1df68bfb4c0626ad5335ec5ee0c594c315b08a61e7f0bc8ce5b264136eec0db17db1e55f1bb0f1de67f9bb9c57bea77feef74f2baa2c@192.168.3.11:20630",
"enode://a1a37849c8a0d5247870fc2d70da053fdae503b99498daf63905728bc801a57818577a88b02895763a5af8037ab5378b3ea12eb01ec2546712cf5ebaab3e94c6@172.16.58.3:20630",
"enode://9b43d046414b722ec3e6237083ab413280555cf4ee5765c9a4c55c9fc86c979c7389840a35377846cf0c6923afa7fa3cd115f6d8152e1f8df24273466cb15cf1@192.168.3.11:20630",
NULL },
// Community
{ NULL },
// Local - Parity
{ NULL },
// Local - Geth
{ NULL }
};
const BREthereumNetwork ethereumMainnet = ðereumMainnetRecord;
/*
// MainnetChainConfig is the chain parameters to run a node on the main network.
MainnetChainConfig = &ChainConfig{
ChainId: big.NewInt(1),
HomesteadBlock: big.NewInt(1150000),
DAOForkBlock: big.NewInt(1920000),
DAOForkSupport: true,
EIP150Block: big.NewInt(2463000),
EIP150Hash: common.HexToHash("0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0"),
EIP155Block: big.NewInt(2675000),
EIP158Block: big.NewInt(2675000),
ByzantiumBlock: big.NewInt(4370000),
Ethash: new(EthashConfig),
}
*/
//
// Testnet
//
static struct BREthereumNetworkRecord ethereumTestnetRecord = {
"Testnet",
3,
3,
EMPTY_HASH_INIT,
EMPTY_HASH_INIT,
// Seeds
{ //"seed.ropsten.eth.brd.breadwallet.com",
//"seed.ropsten.eth.community.breadwallet.com",
NULL },
// Enodes
// BRD
{ "enode://5e1d6f9f74e33b2d1e2fda87efaf60a788b338c08eefd3a435e9c7de98645bc041421c27d9ed3927c7b5195febd691aff30de881842749f3030089df0e135232@192.168.3.11:20630",
"enode://30dc2b7986e2ec5902498ec26fad6fcecece617aa1652f227f684ede6a0939bb7a205ada1c91420d30b427c86bbdcc31fdfd6d955dd8f5854370f583025a0708@192.168.3.11:20630",
"enode://b0357d45e9070c1660f63f077e0e3b0054a18d93785589d498586b6e0b7ec7c5b39ef608e82e7280ca95019db7c36455275d98a3e8684916ba8f3a7aab4ad38b@172.16.31.10:20630",
NULL },
{ NULL },
{ NULL },
{ NULL }
};
const BREthereumNetwork ethereumTestnet = ðereumTestnetRecord;
/*
// TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network.
TestnetChainConfig = &ChainConfig{
ChainId: big.NewInt(3),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(0),
EIP150Hash: common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
EIP155Block: big.NewInt(10),
EIP158Block: big.NewInt(10),
ByzantiumBlock: big.NewInt(1700000),
Ethash: new(EthashConfig),
}
*/
//
// Rinkeby
//
static struct BREthereumNetworkRecord ethereumRinkebyRecord = {
"Rinkeby",
4,
4,
EMPTY_HASH_INIT,
EMPTY_HASH_INIT,
// Seeds
{ NULL },
// Enodes
{ "enode://fe44bc423f210805daad60cc5d308f449e9282c28a9aba91040d7c727cf5751d1ae9e85d32a430f4a6fe15c8eb52833a1747e8b28e6ed5ae291fdae32e6b9181@192.168.127.12:20630",
"enode://777e2a86687d675c05344acc6e24cefbd3e233759e8b89d7b3d101aeffc89e6292f66a115c5bfc30f250c120e6a2354a7a6ea304439cfded706de1c9ade61abf@192.168.127.12:20630",
"enode://deb84117dada6c2c8f9c5d9d44f749b6fbbefdc987a1611b683ead6e4e2ce8e0d05a196591a713376eee5d9c165d3888d2e175e8eb842e5a381f273c0268edca@192.168.127.12:20630",
NULL },
{ NULL },
{ NULL },
{ NULL }
};
const BREthereumNetwork ethereumRinkeby = ðereumRinkebyRecord;
/*
// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
RinkebyChainConfig = &ChainConfig{
ChainId: big.NewInt(4),
HomesteadBlock: big.NewInt(1),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Block: big.NewInt(2),
EIP150Hash: common.HexToHash("0x9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
EIP155Block: big.NewInt(3),
EIP158Block: big.NewInt(3),
ByzantiumBlock: big.NewInt(1035301),
Clique: &CliqueConfig{
Period: 15,
Epoch: 30000,
},
}
*/
/// MARK: - Trusted Checkpoints
/*
// trustedCheckpoint represents a set of post-processed trie roots (CHT and BloomTrie) associated with
// the appropriate section index and head hash. It is used to start light syncing from this checkpoint
// and avoid downloading the entire header chain while still being able to securely access old headers/logs.
type trustedCheckpoint struct {
name string
sectionIdx uint64
sectionHead, chtRoot, bloomTrieRoot common.Hash
}
var (
mainnetCheckpoint = trustedCheckpoint{
name: "mainnet",
sectionIdx: 153,
sectionHead: common.HexToHash("04c2114a8cbe49ba5c37a03cc4b4b8d3adfc0bd2c78e0e726405dd84afca1d63"),
chtRoot: common.HexToHash("d7ec603e5d30b567a6e894ee7704e4603232f206d3e5a589794cec0c57bf318e"),
bloomTrieRoot: common.HexToHash("0b139b8fb692e21f663ff200da287192201c28ef5813c1ac6ba02a0a4799eef9"),
}
ropstenCheckpoint = trustedCheckpoint{
name: "ropsten",
sectionIdx: 79,
sectionHead: common.HexToHash("1b1ba890510e06411fdee9bb64ca7705c56a1a4ce3559ddb34b3680c526cb419"),
chtRoot: common.HexToHash("71d60207af74e5a22a3e1cfbfc89f9944f91b49aa980c86fba94d568369eaf44"),
bloomTrieRoot: common.HexToHash("70aca4b3b6d08dde8704c95cedb1420394453c1aec390947751e69ff8c436360"),
}
)
// trustedCheckpoints associates each known checkpoint with the genesis hash of the chain it belongs to
var trustedCheckpoints = map[common.Hash]trustedCheckpoint{
params.MainnetGenesisHash: mainnetCheckpoint,
params.TestnetGenesisHash: ropstenCheckpoint,
}
// Rinkeby: genesis for all intents and purposes.
// > INFO [06-06|11:34:07] Block synchronisation started
// INFO [06-06|11:34:08] Imported new block headers count=192 elapsed=76.267ms number=192 hash=8c570c…ba360c ignored=0
*/
static void
networkInitilizeAllIfAppropriate (void) {
static int needsInitialization = 1;
if (needsInitialization) {
// Mainnet
ethereumMainnetRecord.genesisBlockHeaderHash =
hashCreate ("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3");
ethereumMainnetRecord.trustedCheckpointBlockHeaderHash =
hashCreate("0x04c2114a8cbe49ba5c37a03cc4b4b8d3adfc0bd2c78e0e726405dd84afca1d63");
// Testnet / 'Ropsten'
ethereumTestnetRecord.genesisBlockHeaderHash =
hashCreate("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d");
ethereumTestnetRecord.trustedCheckpointBlockHeaderHash =
hashCreate("0x1b1ba890510e06411fdee9bb64ca7705c56a1a4ce3559ddb34b3680c526cb419");
// Rinkeby
ethereumRinkebyRecord.genesisBlockHeaderHash =
hashCreate("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177");
ethereumRinkebyRecord.trustedCheckpointBlockHeaderHash =
hashCreate("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177");
// Notable RACE
needsInitialization = 0;
}
}
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/ewm/BREthereumWallet.h
|
//
// BBREthereumWallet.h
// breadwallet-core Ethereum
//
// Created by <NAME> on 2/21/2018.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#ifndef BR_Ethereum_Wallet_H
#define BR_Ethereum_Wallet_H
#include "ethereum/blockchain/BREthereumBlockChain.h"
#include "BREthereumBase.h"
#include "BREthereumAccount.h"
#include "BREthereumTransfer.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* Create a wallet holding ETH; will use the account's primary address.
*
* @param account
* @return
*/
extern BREthereumWallet
walletCreate(BREthereumAccount account,
BREthereumNetwork network);
/**
* Create a Wallet holding Token; will use the account's primary address.
*
* @param account
* @param token
* @return
*/
extern BREthereumWallet
walletCreateHoldingToken(BREthereumAccount account,
BREthereumNetwork network,
BREthereumToken token);
extern void
walletRelease (BREthereumWallet wallet);
extern void
walletsRelease (OwnershipGiven BRArrayOf(BREthereumWallet) wallets);
/**
* Estimate the transfer fee (in Ether) for transferring amount. The estimate uses
* the wallet's default gasPrice and the amount's default gas.
*/
extern BREthereumEther
walletEstimateTransferFee (BREthereumWallet wallet,
BREthereumAmount amount,
int *overflow);
/**
* Estimate the transfer fee (in Ether) for transferring amount.
*/
extern BREthereumEther
walletEstimateTransferFeeDetailed (BREthereumWallet wallet,
BREthereumAmount amount,
BREthereumGasPrice price,
BREthereumGas gas,
int *overflow);
/**
*
* @param wallet
* @param recvAddress
* @param amount
* @return
*/
extern BREthereumTransfer
walletCreateTransfer(BREthereumWallet wallet,
BREthereumAddress recvAddress,
BREthereumAmount amount);
extern BREthereumTransfer
walletCreateTransferWithFeeBasis (BREthereumWallet wallet,
BREthereumAddress recvAddress,
BREthereumAmount amount,
BREthereumFeeBasis feeBasis);
extern BREthereumTransfer
walletCreateTransferGeneric(BREthereumWallet wallet,
BREthereumAddress recvAddress,
BREthereumEther amount,
BREthereumGasPrice gasPrice,
BREthereumGas gasLimit,
const char *data);
extern void
walletSignTransfer(BREthereumWallet wallet,
BREthereumTransfer transfer,
const char *paperKey);
extern void
walletSignTransferWithPrivateKey(BREthereumWallet wallet,
BREthereumTransfer transfer,
BRKey privateKey);
#ifdef WALLET_NEED_RAW
/**
* For `transfer`, get the 'signed transfer data' suitable for use in the RPC-JSON Ethereum
* method `eth_sendRawTransfer` (once hex-encoded).
*
* @param wallet
* @param transfer
* @return
*/
extern BRRlpData // uint8_t, EthereumByteArray
walletGetRawTransfer(BREthereumWallet wallet,
BREthereumTransfer transfer);
/**
* For `transfer`, get the `signed transation data`, encoded in hex with an optional prefix
* (typically "0x"), suitable for use in the RPC-JSON Ethereum method 'eth_sendRawTransfer"
*
*/
extern char *
walletGetRawTransferHexEncoded (BREthereumWallet wallet,
BREthereumTransfer transfer,
const char *prefix);
#endif // WALLET_NEED_RAW
/**
*
*/
extern BREthereumAddress
walletGetAddress(BREthereumWallet wallet);
/**
* The wallet's amount type: ETHER or TOKEN
*/
extern BREthereumAmountType
walletGetAmountType (BREthereumWallet wallet);
/**
* The wallet's token or NULL if the wallet holds ETHER.
*/
extern BREthereumToken
walletGetToken (BREthereumWallet wallet);
/**
* The wallet's balance
*/
extern BREthereumAmount
walletGetBalance (BREthereumWallet wallet);
/**
* Get the wallet's default Gas Limit.
*
* @param wallet
* @return
*/
extern BREthereumGas
walletGetDefaultGasLimit(BREthereumWallet wallet);
/**
* Set the wallet's default Gas Limit. When creating a transfer, unless otherwise specified,
* this GasLimit is used. The default value depends on the wallet type: ETH, ERC20 Token or
* Contract; therefore, set it carefully.
*
* @param wallet
* @param gasLimit
*/
extern void
walletSetDefaultGasLimit(BREthereumWallet wallet, BREthereumGas gasLimit);
/**
* Gets the wallet's default Gas Price.
*
* @param wallet
* @return
*/
extern BREthereumGasPrice
walletGetDefaultGasPrice(BREthereumWallet wallet);
/**
* Sets the wallets' default Gas Price.
*
* @param wallet
* @param gasPrice
*/
extern void
walletSetDefaultGasPrice(BREthereumWallet wallet, BREthereumGasPrice gasPrice);
//
// Transfers
//
typedef int (*BREthereumTransferPredicate) (void *context, BREthereumTransfer transfer, unsigned int index);
typedef void (*BREthereumTransferWalker) (void *context, BREthereumTransfer transfer, unsigned int index);
extern int
transferPredicateAny (void *ignore,
BREthereumTransfer transfer,
unsigned int index);
extern int
transferPredicateStatus (BREthereumTransferStatus status,
BREthereumTransfer transfer,
unsigned int index);
extern void
walletWalkTransfers (BREthereumWallet wallet,
void *context,
BREthereumTransferPredicate predicate,
BREthereumTransferWalker walker);
extern BREthereumTransfer
walletGetTransferByIdentifier (BREthereumWallet wallet,
BREthereumHash hash);
extern BREthereumTransfer
walletGetTransferByOriginatingHash (BREthereumWallet wallet,
BREthereumHash hash);
extern BREthereumTransfer
walletGetTransferByNonce(BREthereumWallet wallet,
BREthereumAddress sourceAddress,
uint64_t nonce);
extern BREthereumTransfer
walletGetTransferByIndex(BREthereumWallet wallet,
uint64_t index);
extern unsigned long
walletGetTransferCount (BREthereumWallet wallet);
//
// Private
// TODO: Make 'static'
//
// Returns Ether appropriate for encoding a transaction. If the transaction is for a TOKEN,
// then the returned Ether is zero (because the amount of a TOKEN transfer is encoded in the
// contract's function call, in the transaction.data field).
private_extern BREthereumEther
transferGetEffectiveAmountInEther (BREthereumTransfer transfer);
private_extern void
walletSetBalance (BREthereumWallet wallet,
BREthereumAmount balance);
private_extern void
walletUpdateBalance (BREthereumWallet wallet);
private_extern void
walletTransferSubmitted (BREthereumWallet wallet,
BREthereumTransfer transaction,
const BREthereumHash hash); // ....
private_extern void
walletTransferIncluded(BREthereumWallet wallet,
BREthereumTransfer transaction,
BREthereumGas gasUsed,
BREthereumHash blockHash,
uint64_t blockNumber,
uint64_t blockTransactionIndex);
private_extern void
walletTransferErrored (BREthereumWallet wallet,
BREthereumTransfer transaction,
const char *reason);
private_extern void
walletHandleTransfer (BREthereumWallet wallet,
BREthereumTransfer transfer);
private_extern void
walletUnhandleTransfer (BREthereumWallet wallet,
BREthereumTransfer transaction);
private_extern int
walletHasTransfer (BREthereumWallet wallet,
BREthereumTransfer transaction);
#ifdef __cplusplus
}
#endif
#endif /* BR_Ethereum_Wallet_H */
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/SpvService/CoreSpvService.h
|
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_CORESPVSERVICE_H__
#define __ELASTOS_SDK_CORESPVSERVICE_H__
#include "Executor.h"
#include <P2P/PeerManager.h>
#include <Account/SubAccount.h>
#include <Wallet/Wallet.h>
namespace Elastos {
namespace ElaWallet {
class ChainParams;
class ChainConfig;
typedef boost::shared_ptr<ChainParams> ChainParamsPtr;
typedef boost::shared_ptr<ChainConfig> ChainConfigPtr;
class CoreSpvService :
public Wallet::Listener,
public PeerManager::Listener {
public:
CoreSpvService();
void Init(const std::string &walletID,
const std::string &chainID,
const SubAccountPtr &subAccount,
time_t earliestPeerTime,
const ChainConfigPtr &config,
const std::string &netType,
const DatabaseManagerPtr &database);
virtual ~CoreSpvService();
virtual const WalletPtr &GetWallet() const;
virtual const PeerManagerPtr &GetPeerManager() const;
public: //override from Wallet
virtual void onBalanceChanged(const uint256 &asset, const BigInt &balance);
virtual void onTxAdded(const TransactionPtr &transaction);
virtual void onTxUpdated(const std::vector<TransactionPtr> &txns);
virtual void onTxDeleted(const TransactionPtr &tx, bool notifyUser, bool recommendRescan);
virtual void onAssetRegistered(const AssetPtr &asset, uint64_t amount, const uint168 &controller);
public: //override from PeerManager
virtual void syncStarted();
virtual void syncProgress(uint32_t progress, time_t lastBlockTime, uint32_t bytesPerSecond, const std::string &downloadPeer);
virtual void syncStopped(const std::string &error);
virtual void txStatusUpdate();
virtual void saveBlocks(bool replace, const std::vector<MerkleBlockPtr> &blocks);
virtual void savePeers(bool replace, const std::vector<PeerInfo> &peers);
virtual void saveBlackPeer(const PeerInfo &peer);
virtual bool networkIsReachable();
virtual void txPublished(const std::string &hash, const nlohmann::json &result);
virtual void connectStatusChanged(const std::string &status);
protected:
virtual void DeleteTxn(const uint256 &hash);
virtual std::vector<TransactionPtr> loadCoinbaseTxns(const std::string &chainID);
virtual std::vector<TransactionPtr> loadConfirmedTxns(const std::string &chainID);
virtual std::vector<TransactionPtr> loadPendingTxns(const std::string &chainID);
virtual std::vector<MerkleBlockPtr> loadBlocks(const std::string &chainID);
virtual std::vector<PeerInfo> loadPeers();
virtual std::set<PeerInfo> loadBlackPeers();
virtual std::vector<AssetPtr> loadAssets();
typedef boost::shared_ptr<PeerManager::Listener> PeerManagerListenerPtr;
virtual const PeerManagerListenerPtr &createPeerManagerListener();
typedef boost::shared_ptr<Wallet::Listener> WalletListenerPtr;
virtual const WalletListenerPtr &createWalletListener();
protected:
WalletPtr _wallet; // Optional<BRCoreWallet>
WalletListenerPtr _walletListener;
PeerManagerPtr _peerManager; // Optional<BRCorePeerManager>
PeerManagerListenerPtr _peerManagerListener;
};
// Callbacks from JNI code that throw an exception are QUIETLY SWALLOWED. We'll provide
// a wrapper class, implementing each Listener used for callbacks. The wrapper class
// will catch any exception and issue some warning, or something.
class WrappedExceptionPeerManagerListener :
public PeerManager::Listener {
public:
WrappedExceptionPeerManagerListener(PeerManager::Listener *listener);
virtual void syncStarted();
virtual void syncProgress(uint32_t progress, time_t lastBlockTime, uint32_t bytesPerSecond, const std::string &downloadPeer);
virtual void syncStopped(const std::string &error);
virtual void txStatusUpdate();
virtual void saveBlocks(bool replace, const std::vector<MerkleBlockPtr> &blocks);
virtual void savePeers(bool replace, const std::vector<PeerInfo> &peers);
virtual void saveBlackPeer(const PeerInfo &peer);
virtual bool networkIsReachable();
virtual void txPublished(const std::string &hash, const nlohmann::json &result);
virtual void connectStatusChanged(const std::string &status);
private:
PeerManager::Listener *_listener;
};
// Callbacks from Core, via JNI, run on a Core thread - they absolutely should not run on a
// Core thread.
class WrappedExecutorPeerManagerListener :
public PeerManager::Listener {
public:
WrappedExecutorPeerManagerListener(PeerManager::Listener *listener,
Executor *executor);
virtual void syncStarted();
virtual void syncProgress(uint32_t progress, time_t lastBlockTime, uint32_t bytesPerSecond, const std::string &downloadPeer);
virtual void syncStopped(const std::string &error);
virtual void txStatusUpdate();
virtual void saveBlocks(bool replace, const std::vector<MerkleBlockPtr> &blocks);
virtual void savePeers(bool replace, const std::vector<PeerInfo> &peers);
virtual void saveBlackPeer(const PeerInfo &peer);
virtual bool networkIsReachable();
virtual void txPublished(const std::string &hash, const nlohmann::json &result);
virtual void connectStatusChanged(const std::string &status);
private:
PeerManager::Listener *_listener;
Executor *_executor;
};
class WrappedExceptionWalletListener :
public Wallet::Listener {
public:
WrappedExceptionWalletListener(Wallet::Listener *listener);
virtual void onBalanceChanged(const uint256 &asset, const BigInt &balance);
virtual void onTxAdded(const TransactionPtr &transaction);
virtual void onTxUpdated(const std::vector<TransactionPtr> &txns);
virtual void onTxDeleted(const TransactionPtr &tx, bool notifyUser, bool recommendRescan);
virtual void onAssetRegistered(const AssetPtr &asset, uint64_t amount, const uint168 &controller);
private:
Wallet::Listener *_listener;
};
class WrappedExecutorWalletListener :
public Wallet::Listener {
public:
WrappedExecutorWalletListener(Wallet::Listener *listener, Executor *executor);
virtual void onBalanceChanged(const uint256 &asset, const BigInt &balance);
virtual void onTxAdded(const TransactionPtr &transaction);
virtual void onTxUpdated(const std::vector<TransactionPtr> &txns);
virtual void onTxDeleted(const TransactionPtr &tx, bool notifyUser, bool recommendRescan);
virtual void onAssetRegistered(const AssetPtr &asset, uint64_t amount, const uint168 &controller);
private:
Wallet::Listener *_listener;
Executor *_executor;
};
}
}
#endif //__ELASTOS_SDK_CORESPVSERVICE_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Plugin/Transaction/Asset.h
|
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_SPVSDK_ASSET_H
#define __ELASTOS_SDK_SPVSDK_ASSET_H
#include <Plugin/Interface/ELAMessageSerializable.h>
#include <Common/JsonSerializer.h>
namespace Elastos {
namespace ElaWallet {
#define TOKEN_ASSET_PRECISION "1000000000000000000"
class Asset :
public ELAMessageSerializable, public JsonSerializer {
public:
enum AssetType {
Token = 0x00,
Share = 0x01,
};
enum AssetRecordType {
Unspent = 0x00,
Balance = 0x01,
};
const static uint8_t MaxPrecision = 18;
public:
Asset();
Asset(const std::string &name, const std::string &desc, uint8_t precision,
AssetType assetType = Token, AssetRecordType recordType = Unspent);
Asset(const Asset &asset);
~Asset();
Asset &operator=(const Asset &asset);
void SetName(const std::string &name) {
_name = name;
}
const std::string &GetName() const {
return _name;
}
void SetDescription(const std::string &desc) {
_description = desc;
}
const std::string &GetDescription() const {
return _description;
}
void SetAssetType(Asset::AssetType type) {
_assetType = type;
}
Asset::AssetType GetAssetType() const {
return _assetType;
}
void SetAssetRecordType(Asset::AssetRecordType type) {
_recordType = type;
}
Asset::AssetRecordType GetAssetRecordType() const {
return _recordType;
}
void SetPrecision(uint8_t precision) {
_precision = precision;
}
uint8_t GetPrecision() const {
return _precision;
}
virtual size_t EstimateSize() const;
virtual void Serialize(ByteStream &ostream) const;
virtual bool Deserialize(const ByteStream &istream);
virtual nlohmann::json ToJson() const;
virtual void FromJson(const nlohmann::json &jsonData);
const uint256 &GetHash() const;
void SetHash(const uint256 &hash);
public:
static const uint256 &GetELAAssetID();
private:
std::string _name;
std::string _description;
uint8_t _precision;
AssetType _assetType;
AssetRecordType _recordType;
mutable uint256 _hash;
static uint256 _elaAsset;
};
typedef boost::shared_ptr<Asset> AssetPtr;
}
}
#endif //__ELASTOS_SDK_SPVSDK_ASSET_H
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/base/BREthereumData.h
|
<reponame>fakecoinbase/elastosslashElastos.ELA.SPV.Cpp<filename>ThirdParty/breadwallet-core/ethereum/base/BREthereumData.h
//
// BREthereumData.h
// BRCore
//
// Created by <NAME> on 10/3/18.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#ifndef BR_Ethereum_Data_H
#define BR_Ethereum_Data_H
#include "support/BRArray.h"
#include "support/BRSet.h"
#include "ethereum/rlp/BRRlp.h"
#include "BREthereumHash.h"
#ifdef __cplusplus
extern "C" {
#endif
/// MARK: - Data
/**
* Ethereum Data is an pair of { count, bytes} representing an arbitrary array of bytes.
*/
typedef struct {
size_t count;
uint8_t *bytes;
} BREthereumData;
extern BREthereumData
dataCreateFromBytes (size_t count,
uint8_t *bytes,
int takeBytes);
extern BREthereumData
dataCreateFromRlpData (BRRlpData rlp,
int takeBytes);
extern BREthereumData // invert dataAsString()
dataCreateFromString (const char *string) ;
extern BREthereumData
dataCopy (BREthereumData data);
extern void
dataRelease (BREthereumData data);
// hex-encoded data; you own this.
extern char *
dataAsString (BREthereumData data);
extern BRRlpData
dataAsRlpData (BREthereumData data);
/// MARK: - Hash Data Pair
/**
* An Ethereum Hash Data Pair holds {Hash, Data} where the hash can be considered a unique
* identifier for the Data
*/
typedef struct BREthereumHashDataPairRecord *BREthereumHashDataPair;
/**
* Create a BREthereumHashDataPair
*
* @note Takes ownership of `data` which must have been created with `takeBytes` (because
* on `hashDataPairRelease()` the `data` will itself be released.
*
* @param hash the hash
* @param data the data
* @return the hash-data-pair
*/
extern BREthereumHashDataPair
hashDataPairCreate (BREthereumHash hash,
BREthereumData data);
extern BREthereumHashDataPair
hashDataPairCreateFromString (const char *hashString,
const char *dataString);
extern void
hashDataPairRelease (BREthereumHashDataPair pair);
static inline void
hashDataPairReleaseForSet (void *ignore, void *item) {
hashDataPairRelease((BREthereumHashDataPair) item);
}
extern BREthereumHash
hashDataPairGetHash (BREthereumHashDataPair pair);
// The hex-encoded hash. You own this.
extern char *
hashDataPairGetHashAsString (BREthereumHashDataPair pair);
// YOU DO NOT OWN THE RETURNED DATA
extern BREthereumData
hashDataPairGetData (BREthereumHashDataPair pair);
// The hex-encoded data. You own this.
extern char *
hashDataPairGetDataAsString (BREthereumHashDataPair pair);
extern void
hashDataPairExtractStrings (BREthereumHashDataPair pair,
char **hashAsString,
char **dataAsString);
extern size_t
hashDataPairHashValue (const void *t);
extern int
hashDataPairHashEqual (const void *t1,
const void *t2);
/// MARK: - Hash Data Pair Set
extern BRSetOf (BREthereumHashDataPair)
hashDataPairSetCreateEmpty (size_t count);
/**
* Create a BRSet of BREthereumHashDataPair.
*
* @note This function takes ownership of `pairs` (that is, owns the individual
* pair items and frees the pairs array.
*
* @param BREthereumHashDataPair array of pairs to add to the set.
* @return a BRSET of BREthereumHashDataPair
*/
extern BRSetOf (BREthereumHashDataPair)
hashDataPairSetCreate (BRArrayOf(BREthereumHashDataPair) pairs);;
extern void
hashDataPairSetRelease (BRSetOf (BREthereumHashDataPair) set);
extern void
hashDataPairAdd (BRSetOf(BREthereumHashDataPair) set,
const char *hash,
const char *data);
#ifdef __cplusplus
}
#endif
#endif /* BR_Ethereum_Data_H */
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Plugin/Transaction/Payload/OutputPayload/PayloadVote.h
|
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_OUTPUT_PAYLOADVOTE_H
#define __ELASTOS_SDK_OUTPUT_PAYLOADVOTE_H
#include <Plugin/Transaction/Payload/OutputPayload/IOutputPayload.h>
#include <Common/BigInt.h>
#define VOTE_PRODUCER_CR_VERSION 0x01
namespace Elastos {
namespace ElaWallet {
class CandidateVotes {
public:
CandidateVotes();
explicit CandidateVotes(const bytes_t &candidate, const BigInt &votes = 0);
~CandidateVotes();
public:
const bytes_t & GetCandidate() const;
const BigInt &GetVotes() const;
void SetVotes(uint64_t votes);
void Serialize(ByteStream &ostream, uint8_t version) const;
bool Deserialize(const ByteStream &istream, uint8_t version);
nlohmann::json ToJson(uint8_t version) const;
void FromJson(const nlohmann::json &j, uint8_t version);
private:
bytes_t _candidate;
BigInt _votes;
};
class VoteContent {
public:
enum Type {
Delegate,
CRC,
CRCProposal,
CRCImpeachment,
Max,
};
VoteContent();
VoteContent(Type t);
VoteContent(Type t, const std::vector<CandidateVotes> &c);
~VoteContent();
public:
void AddCandidate(const CandidateVotes &candidateVotes);
const Type &GetType() const;
std::string GetTypeString() const;
void SetCandidateVotes(const std::vector<CandidateVotes> &candidateVotes);
const std::vector<CandidateVotes> &GetCandidateVotes() const;
void SetAllCandidateVotes(uint64_t votes);
BigInt GetMaxVoteAmount() const;
BigInt GetTotalVoteAmount() const;
void Serialize(ByteStream &ostream, uint8_t version) const;
bool Deserialize(const ByteStream &istream, uint8_t version);
nlohmann::json ToJson(uint8_t version) const;
void FromJson(const nlohmann::json &j, uint8_t version);
private:
Type _type;
std::vector<CandidateVotes> _candidates;
};
typedef std::vector<VoteContent> VoteContentArray;
class PayloadVote : public IOutputPayload {
public:
PayloadVote(uint8_t version = 0);
PayloadVote(const std::vector<VoteContent> &voteContents, uint8_t version = 0);
PayloadVote(const PayloadVote &payload);
~PayloadVote();
void SetVoteContent(const std::vector<VoteContent> &voteContent);
const std::vector<VoteContent> &GetVoteContent() const;
uint8_t Version() const;
virtual size_t EstimateSize() const;
virtual void Serialize(ByteStream &ostream) const;
virtual bool Deserialize(const ByteStream &istream);
virtual nlohmann::json ToJson() const;
virtual void FromJson(const nlohmann::json &j);
virtual IOutputPayload &operator=(const IOutputPayload &payload);
virtual PayloadVote &operator=(const PayloadVote &payload);
private:
uint8_t _version;
std::vector<VoteContent> _content;
};
}
}
#endif //__ELASTOS_SDK_OUTPUT_PAYLOADVOTE_H
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
Interface/MasterWalletManager.h
|
<gh_stars>0
/*
* Copyright (c) 2019 Elastos Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __ELASTOS_SDK_MASTERWALLETMANAGER_H__
#define __ELASTOS_SDK_MASTERWALLETMANAGER_H__
#include <map>
#include "IMasterWalletManager.h"
namespace Elastos {
namespace ElaWallet {
class Config;
class Lockable;
class SPV_API_PUBLIC MasterWalletManager : public IMasterWalletManager {
public:
/**
* Constructor
* @param rootPath Specify directory for all config files, including mnemonic config files. Root should not be empty, otherwise will throw invalid argument exception.
* @param netType Value can only be one of "MainNet", "TestNet", "RegTest", "PrvNet"
* @param dataPath The path contains data of wallet created. If empty, data of wallet will store in rootPath.
* @param config If netType is "MainNet" or "TestNet" or "RegTest", config will be ignore.
*
* If netType is "PrvNet", config must be provided as below:
* {
* "ELA": {
* "GenesisAddress": "",
* "ChainParameters": {
* "MagicNumber": 20190808,
* "StandardPort": 30018,
* "DNSSeeds": [ "172.26.0.165" ],
* "CheckPoints": [
* [0, "8df798783097be3a8f382f6537e47c7168d4bf4d741fa3fa8c48c607a06352cf", 1513936800, 486801407]
* ]
* }
* },
* "IDChain": {
* "GenesisAddress": "XKUh4GLhFJiqAMTF6HyWQrV9pK9HcGUdfJ",
* "ChainParameters": {
* "MagicNumber": 20190816,
* "StandardPort": 30138,
* "DNSSeeds": [ "172.26.0.165" ],
* "CheckPoints": [
* [0, "56be936978c261b2e649d58dbfaf3f23d4a868274f5522cd2adb4308a955c4a3", 1513936800, 486801407]
* ]
* }
* }
* }
*/
explicit MasterWalletManager(const std::string &rootPath, const std::string &netType = "MainNet",
const nlohmann::json &config = nlohmann::json(),
const std::string &dataPath = "");
virtual ~MasterWalletManager();
virtual std::string GenerateMnemonic(const std::string &language, int wordCount = 12) const;
virtual IMasterWallet *CreateMasterWallet(
const std::string &masterWalletID,
const std::string &mnemonic,
const std::string &phrasePassword,
const std::string &payPassword,
bool singleAddress);
virtual IMasterWallet *CreateMultiSignMasterWallet(
const std::string &masterWalletID,
const nlohmann::json &cosigners,
uint32_t m,
bool singleAddress,
bool compatible = false,
time_t timestamp = 0);
virtual IMasterWallet *CreateMultiSignMasterWallet(
const std::string &masterWalletID,
const std::string &xprv,
const std::string &payPassword,
const nlohmann::json &cosigners,
uint32_t m,
bool singleAddress,
bool compatible = false,
time_t timestamp = 0);
virtual IMasterWallet *CreateMultiSignMasterWallet(
const std::string &masterWalletID,
const std::string &mnemonic,
const std::string &passphrase,
const std::string &payPassword,
const nlohmann::json &cosigners,
uint32_t m,
bool singleAddress,
bool compatible = false,
time_t timestamp = 0);
virtual std::vector<IMasterWallet *> GetAllMasterWallets() const;
virtual std::vector<std::string> GetAllMasterWalletID() const;
virtual bool WalletLoaded(const std::string &masterWalletID) const;
virtual IMasterWallet *GetMasterWallet(
const std::string &masterWalletID) const;
virtual void DestroyWallet(
const std::string &masterWalletID);
virtual IMasterWallet *ImportWalletWithKeystore(
const std::string &masterWalletID,
const nlohmann::json &keystoreContent,
const std::string &backupPassword,
const std::string &payPassword);
virtual IMasterWallet *ImportWalletWithMnemonic(
const std::string &masterWalletID,
const std::string &mnemonic,
const std::string &phrasePassword,
const std::string &payPassword,
bool singleAddress,
time_t timestamp = 0);
virtual IMasterWallet *ImportReadonlyWallet(
const std::string &masterWalletID,
const nlohmann::json &walletJson);
virtual std::string GetVersion() const;
virtual void FlushData();
protected:
typedef std::map<std::string, IMasterWallet *> MasterWalletMap;
MasterWalletManager(const MasterWalletMap &walletMap, const std::string &rootPath,
const std::string &dataPath);
void LoadMasterWalletID();
IMasterWallet *LoadMasterWallet(const std::string &masterWalletID) const;
void checkRedundant(IMasterWallet *wallet) const;
protected:
Lockable *_lock;
Config *_config;
std::string _rootPath;
std::string _dataPath;
bool _p2pEnable;
mutable MasterWalletMap _masterWalletMap;
};
}
}
#endif //__ELASTOS_SDK_MASTERWALLETMANAGER_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/les/BREthereumMessage.c
|
//
// BREthereumLESMessage.c
// Core
//
// Created by <NAME> on 8/13/18.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#include <assert.h>
#include <sys/socket.h>
#include "BREthereumMessage.h"
/// MARK: - Wire Protocol Messagees
extern BRRlpItem
messageEncode (BREthereumMessage message,
BREthereumMessageCoder coder) {
switch (message.identifier) {
case MESSAGE_P2P: return messageP2PEncode (message.u.p2p, coder);
case MESSAGE_DIS: return messageDISEncode (message.u.dis, coder);
case MESSAGE_ETH: assert (0);
case MESSAGE_LES: return messageLESEncode (message.u.les, coder);
case MESSAGE_PIP: return messagePIPEncode(message.u.pip, coder);
}
}
extern BREthereumMessage
messageDecode (BRRlpItem item,
BREthereumMessageCoder coder,
BREthereumMessageIdentifier type,
BREthereumANYMessageIdentifier subtype) {
switch (type) {
case MESSAGE_P2P:
return (BREthereumMessage) {
MESSAGE_P2P,
{ .p2p = messageP2PDecode (item, coder, (BREthereumP2PMessageIdentifier) subtype) }
};
case MESSAGE_DIS:
return (BREthereumMessage) {
MESSAGE_DIS,
{ .dis = messageDISDecode (item, coder) }
};
case MESSAGE_ETH:
assert (0);
case MESSAGE_LES:
return (BREthereumMessage) {
MESSAGE_LES,
{ .les = messageLESDecode (item, coder, (BREthereumLESMessageIdentifier) subtype) }
};
case MESSAGE_PIP:
return (BREthereumMessage) {
MESSAGE_PIP,
{ .pip = messagePIPDecode (item, coder, (BREthereumPIPMessageType) subtype) }
};
}
}
extern int
messageHasIdentifier (BREthereumMessage *message,
BREthereumMessageIdentifier identifer) {
return identifer == message->identifier;
}
extern int
messageHasIdentifiers (BREthereumMessage *message,
BREthereumMessageIdentifier identifer,
BREthereumANYMessageIdentifier anyIdentifier) {
if (identifer != message->identifier) return 0;
switch (message->identifier) {
case MESSAGE_P2P: return anyIdentifier == message->u.p2p.identifier;
case MESSAGE_DIS: return anyIdentifier == message->u.dis.identifier;
case MESSAGE_ETH: return anyIdentifier == message->u.eth.identifier;
case MESSAGE_LES: return anyIdentifier == message->u.les.identifier;
case MESSAGE_PIP: return anyIdentifier == message->u.pip.type;
}
}
static const char *messageNames[] = { "P2P", "DIS", "ETH", "LES", "PIP" };
const char *
messageGetIdentifierName (BREthereumMessage *message) {
return messageNames [message->identifier];
}
const char *
messageGetAnyIdentifierName (BREthereumMessage *message) {
switch (message->identifier) {
case MESSAGE_P2P: return messageP2PGetIdentifierName (message->u.p2p.identifier);
case MESSAGE_DIS: return messageDISGetIdentifierName (message->u.dis.identifier);
case MESSAGE_ETH: return "";
case MESSAGE_LES: return messageLESGetIdentifierName (message->u.les.identifier);
case MESSAGE_PIP: return messagePIPGetIdentifierName (message->u.pip);
}
}
extern void
messageRelease (BREthereumMessage *message) {
switch (message->identifier) {
case MESSAGE_P2P:
messageP2PRelease (&message->u.p2p);
break;
case MESSAGE_DIS:
messageDISRelease (&message->u.dis);
break;
case MESSAGE_ETH:
break;
case MESSAGE_LES:
messageLESRelease (&message->u.les);
break;
case MESSAGE_PIP:
messagePIPRelease (&message->u.pip);
break;
}
}
extern void
messagesRelease (BRArrayOf(BREthereumMessage) messages) {
if (NULL != messages) {
size_t count = array_count(messages);
for (size_t index = 0; index < count; index++)
messageRelease (&messages[index]);
array_free (messages);
}
}
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Wallet/Wallet.h
|
<reponame>fakecoinbase/elastosslashElastos.ELA.SPV.Cpp<filename>SDK/Wallet/Wallet.h
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_WALLET_H__
#define __ELASTOS_SDK_WALLET_H__
#include <Common/Lockable.h>
#include <Common/ElementSet.h>
#include <Account/SubAccount.h>
#include <Wallet/GroupedAsset.h>
#include <Plugin/Transaction/TransactionInput.h>
#include <boost/weak_ptr.hpp>
#include <boost/function.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <string>
#include <map>
#define TX_FEE_PER_KB 1000ULL // standard tx fee per kb of tx size, rounded up to nearest kb
#define TX_OUTPUT_SIZE 34 // estimated size for a typical transaction output
#define TX_INPUT_SIZE 148 // estimated size for a typical compact pubkey transaction input
#define TX_MAX_SIZE 120000 // no tx can be larger than this size in bytes
#define TX_UNCONFIRMED INT32_MAX
#define DEFAULT_FEE_PER_KB (10000) // 10 satoshis-per-byte
#define MIN_FEE_PER_KB TX_FEE_PER_KB // bitcoind 0.12 default min-relay fee
#define MAX_FEE_PER_KB ((TX_FEE_PER_KB*1000100 + 190)/191) // slightly higher than a 10,000bit fee on a 191byte tx
#define TX_MAX_LOCK_HEIGHT 500000000 // a lockTime below this value is a block height, otherwise a timestamp
#define TX_MIN_OUTPUT_AMOUNT (TX_FEE_PER_KB*3*(TX_OUTPUT_SIZE + TX_INPUT_SIZE)/1000) //no txout can be below this amount
namespace Elastos {
namespace ElaWallet {
class Transaction;
class TransactionOutput;
class TransactionInput;
class Address;
class Asset;
class IPayload;
class UTXO;
class IOutputPayload;
class DatabaseManager;
typedef boost::shared_ptr<Asset> AssetPtr;
typedef boost::shared_ptr<Transaction> TransactionPtr;
typedef boost::shared_ptr<IPayload> PayloadPtr;
typedef boost::shared_ptr<UTXO> UTXOPtr;
typedef std::vector<UTXOPtr> UTXOArray;
typedef boost::shared_ptr<TransactionOutput> OutputPtr;
typedef boost::shared_ptr<TransactionInput> InputPtr;
typedef boost::shared_ptr<IOutputPayload> OutputPayloadPtr;
typedef boost::shared_ptr<DatabaseManager> DatabaseManagerPtr;
typedef boost::weak_ptr<DatabaseManager> DatabaseManagerWeakPtr;
enum TxnType {
TXN_NORMAL = 0x01,
TXN_PENDING = 0x02,
TXN_COINBASE = 0x04
};
class Wallet : public Lockable {
public:
class Listener {
public:
virtual void onBalanceChanged(const uint256 &asset, const BigInt &balance) = 0;
virtual void onTxAdded(const TransactionPtr &tx) = 0;
virtual void onTxUpdated(const std::vector<TransactionPtr> &txns) = 0;
virtual void onTxDeleted(const TransactionPtr &tx, bool notifyUser, bool recommendRescan) = 0;
virtual void onAssetRegistered(const AssetPtr &asset, uint64_t amount, const uint168 &controller) = 0;
};
public:
Wallet(uint32_t lastBlockHeight,
const std::string &walletID,
const std::string &chainID,
const SubAccountPtr &subAccount,
const boost::shared_ptr<Wallet::Listener> &listener,
const DatabaseManagerPtr &database);
virtual ~Wallet();
void ClearData();
void GenerateCID();
nlohmann::json GetBasicInfo() const;
const std::string &GetWalletID() const;
void SetBlockHeight(uint32_t height);
uint32_t LastBlockHeight() const;
nlohmann::json GetBalanceInfo();
BigInt GetBalanceWithAddress(const uint256 &assetID, const std::string &addr) const;
// returns the first unused external address
AddressPtr GetReceiveAddress() const;
size_t GetAllAddresses(AddressArray &addr, uint32_t start, size_t count, bool internal) const;
size_t GetAllCID(AddressArray &cid, uint32_t start, size_t count) const;
size_t GetAllPublickeys(std::vector<bytes_t> &pubkeys, uint32_t start, size_t count, bool containInternal);
AddressPtr GetOwnerDepositAddress() const;
AddressPtr GetCROwnerDepositAddress() const;
AddressPtr GetOwnerAddress() const;
AddressArray GetAllSpecialAddresses() const;
bytes_t GetOwnerPublilcKey() const;
bool IsDepositAddress(const AddressPtr &addr) const;
// true if the address was previously generated by BRWalletUnusedAddrs() (even if it's now used)
bool ContainsAddress(const AddressPtr &address);
BigInt GetBalance(const uint256 &assetID) const;
uint64_t GetFeePerKb() const;
void SetFeePerKb(uint64_t fee);
TransactionPtr Vote(const VoteContent &voteContent, const std::string &memo, bool max,
VoteContentArray &dropedVotes);
TransactionPtr Consolidate(const std::string &memo, const uint256 &asset);
TransactionPtr CreateRetrieveTransaction(uint8_t type, const PayloadPtr &payload, const BigInt &amount,
const AddressPtr &fromAddress, const std::string &memo);
TransactionPtr CreateTransaction(uint8_t type, const PayloadPtr &payload,
const AddressPtr &fromAddress, const OutputArray &outputs,
const std::string &memo, bool max = false);
bool ContainsTransaction(const TransactionPtr &transaction);
bool ContainsTransaction(const uint256 &txHash) const;
bool RegisterTransaction(const TransactionPtr &tx);
void RemoveTransaction(const uint256 &transactionHash);
void UpdateTransactions(const std::vector<uint256> &txHashes, uint32_t blockHeight, time_t timestamp);
TransactionPtr TransactionForHash(const uint256 &transactionHash) const;
std::vector<TransactionPtr> GetDPoSTransactions() const;
std::vector<TransactionPtr> GetCRCTransactions() const;
std::vector<TransactionPtr> GetProposalTransactions() const;
std::vector<TransactionPtr> GetDIDTransactions() const;
std::map<uint256, TransactionPtr> TransactionsForInputs(const InputArray &inputs) const;
bool TransactionIsValid(const TransactionPtr &transaction);
#if 0
bool TransactionIsPending(const TransactionPtr &transaction);
bool TransactionIsVerified(const TransactionPtr &transaction);
#endif
BigInt AmountSentByTx(const TransactionPtr &tx);
bool IsReceiveTransaction(const TransactionPtr &tx) const;
bool StripTransaction(const TransactionPtr &tx) const;
void SignTransaction(const TransactionPtr &tx, const std::string &payPassword) const;
std::string SignWithDID(const AddressPtr &did, const std::string &msg, const std::string &payPasswd) const;
std::string SignDigestWithDID(const AddressPtr &did, const uint256 &digest,
const std::string &payPasswd) const;
bytes_t SignWithOwnerKey(const bytes_t &msg, const std::string &payPasswd);
void UpdateLockedBalance();
UTXOArray GetAllUTXO(const std::string &address) const;
UTXOArray GetVoteUTXO() const;
std::vector<TransactionPtr> TxUnconfirmedBefore(uint32_t blockHeight);
void SetTxUnconfirmedAfter(uint32_t blockHeight);
AddressArray UnusedAddresses(uint32_t gapLimit, bool internal);
AssetPtr GetAsset(const uint256 &assetID) const;
nlohmann::json GetAllAssets() const;
bool AssetNameExist(const std::string &name) const;
private:
GroupedAssetPtr GetGroupedAsset(const uint256 &assetID) const;
bool ContainsAsset(const uint256 &assetID) const;
bool ContainsTx(const TransactionPtr &tx) const;
bool ContainsInput(const InputPtr &in) const;
std::vector<UTXOPtr> GetUTXO(const uint256 &assetID, const std::string &addr) const;
bool IsAssetUnique(const std::vector<OutputPtr> &outputs) const;
std::map<uint256, BigInt> BalanceAfterUpdatedTx(const TransactionPtr &tx, UTXOArray &deleted, UTXOArray &added);
std::map<uint256, BigInt> BalanceAfterRemoveTx(const TransactionPtr &tx, UTXOArray &deleted, UTXOArray &added);
void AddSpendingUTXO(const InputArray &inputs);
void RemoveSpendingUTXO(const InputArray &inputs);
void InstallAssets(const std::vector<AssetPtr> &assets);
void InstallDefaultAsset();
bool IsUTXOSpending(const UTXOPtr &utxo) const;
private:
void UTXOUpdated(const UTXOArray &added, const UTXOArray &deleted, bool replace = false);
void balanceChanged(const uint256 &asset, const BigInt &balance);
void txnReplace(const std::vector<TransactionPtr> &txConfirmed,
const std::vector<TransactionPtr> &txPending,
const std::vector<TransactionPtr> &txCoinbase);
void txAdded(const TransactionPtr &tx);
void txUpdated(const std::vector<TransactionPtr> &txns);
void txDeleted(const TransactionPtr &tx, bool notifyUser, bool recommendRescan);
void assetRegistered(const AssetPtr &asset, uint64_t amount, const uint168 &controller);
void usedAddressSaved(const AddressSet &usedAddress, bool replace = false);
std::vector<TransactionPtr> loadTxnAfter(uint32_t height) const;
bool containTxn(const uint256 &hash) const;
std::vector<TransactionPtr> LoadUTXOTxn() const;
std::vector<UTXOPtr> LoadUTXOs() const;
std::vector<AssetPtr> LoadAssets();
AddressSet LoadUsedAddress() const;
void SaveSpecialTxHash(const std::vector<std::string> &txHashDPoS,
const std::vector<std::string> &txHashCRC,
const std::vector<std::string> &txHashProposal,
const std::vector<std::string> &txHashDID,
bool replace = false);
public:
std::vector<TransactionPtr> LoadTxn(TxnType type) const;
TransactionPtr LoadTxn(const uint256 &hash) const;
protected:
friend class GroupedAsset;
std::string _walletID, _chainID;
SubAccountPtr _subAccount;
typedef std::map<uint256, GroupedAssetPtr> GroupedAssetMap;
mutable GroupedAssetMap _groupedAssets;
// typedef ElementSet<TransactionPtr> TransactionSet;
// std::vector<TransactionPtr> _transactions, _coinbaseTransactions;
// TransactionSet _allTx;
DatabaseManagerWeakPtr _database;
UTXOSet _spendingOutputs;
uint64_t _feePerKb;
uint32_t _blockHeight;
boost::weak_ptr<Listener> _listener;
};
typedef boost::shared_ptr<Wallet> WalletPtr;
}
}
#endif //__ELASTOS_SDK_WALLET_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Plugin/Transaction/Payload/SideChainPow.h
|
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_SIDECHAINPOW_H__
#define __ELASTOS_SDK_SIDECHAINPOW_H__
#include "IPayload.h"
#include <Common/uint256.h>
namespace Elastos {
namespace ElaWallet {
class SideChainPow :
public IPayload {
public:
SideChainPow();
SideChainPow(const SideChainPow &payload);
SideChainPow(const uint256 &sideBlockHash, const uint256 &sideGensisHash, uint32_t height, const bytes_t &signedData);
~SideChainPow();
void SetSideBlockHash(const uint256 &sideBlockHash);
void SetSideGenesisHash(const uint256 &sideGensisHash);
void SetBlockHeight(uint32_t height);
void SetSignedData(const bytes_t &signedData);
const uint256 &GetSideBlockHash() const;
const uint256 &GetSideGenesisHash() const;
const uint32_t &GetBlockHeight() const;
const bytes_t &GetSignedData() const;
virtual size_t EstimateSize(uint8_t version) const;
virtual void Serialize(ByteStream &ostream, uint8_t version) const;
virtual bool Deserialize(const ByteStream &istream, uint8_t version);
virtual nlohmann::json ToJson(uint8_t version) const;
virtual void FromJson(const nlohmann::json &j, uint8_t version);
virtual IPayload &operator=(const IPayload &payload);
SideChainPow &operator=(const SideChainPow &payload);
private:
uint256 _sideBlockHash;
uint256 _sideGenesisHash;
uint32_t _blockHeight;
bytes_t _signedData;
};
}
}
#endif //__ELASTOS_SDK_PAYLOADSIDEMINING_H
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/bcs/BREthereumBCS.h
|
<reponame>fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
//
// BREthereumBCS.h
// Core
//
// Created by <NAME> on 5/24/18.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#ifndef BR_Ethereum_BCS_h
#define BR_Ethereum_BCS_h
#include "ethereum/base/BREthereumBase.h"
#include "ethereum/les/BREthereumLES.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* A Block Chain Slice
*
* A Block Chain Slice (BCS) represents a user account-centric view of the Ethereum
* block chain. A BCS maintains the User's transfers (both transactions and logs) for the User as
* either the source or target of the transfer. The maintained transfers must be valid; the
* validation is performed by validating blocks in the block chain.
*
* BCS validates blocks in one or two ways. First, if the block is relatively old, then Geth and
* Parity nodes provide a 'Header Proof' message that returns a proof and the headers total
* difficulty. For Parity 'old' is 2048 block numbers in the past; for Geth 'old' is <what 1024>.
* Second, if the block is relatively new, then BCS chains together individual blocks - to form a
* block chain and to propagate the total difficulty - once each block has itself been validated.
*
* In the end, a transfer is valid of its containing block is valid; that holding no matter how
* the block is validated - using a 'Header Proof' or a block chain.
*
* BCS uses a unique 'nary-search on account state changes w/ augmentation' to identify transfers.
*/
typedef struct BREthereumBCSStruct *BREthereumBCS;
//
// BCS Listener
//
typedef void* BREthereumBCSCallbackContext;
/**
* The BCS block chain has been extended.
*/
typedef void
(*BREthereumBCSCallbackBlockchain) (BREthereumBCSCallbackContext context,
BREthereumHash headBlockHash,
uint64_t headBlockNumber,
uint64_t headBlockTimestamp);
/**
* The BCS account state has been updated.
*/
typedef void
(*BREthereumBCSCallbackAccountState) (BREthereumBCSCallbackContext context,
BREthereumAccountState accountState);
/**
* A BCS Transaction (for `account`) have been updated.
*/
typedef enum {
BCS_CALLBACK_TRANSACTION_ADDED,
BCS_CALLBACK_TRANSACTION_UPDATED,
BCS_CALLBACK_TRANSACTION_DELETED
} BREthereumBCSCallbackTransactionType;
#define BCS_CALLBACK_TRANSACTION_TYPE_NAME( type ) \
((type) == BCS_CALLBACK_TRANSACTION_UPDATED \
? "Updated" \
: ((type) == BCS_CALLBACK_TRANSACTION_ADDED \
? "Added" \
: "Deleted"))
typedef void
(*BREthereumBCSCallbackTransaction) (BREthereumBCSCallbackContext context,
BREthereumBCSCallbackTransactionType event,
OwnershipGiven BREthereumTransaction transaction);
/**
* A BCS Log (for `account`) has been updated.
*/
typedef enum {
BCS_CALLBACK_LOG_ADDED,
BCS_CALLBACK_LOG_UPDATED,
BCS_CALLBACK_LOG_DELETED,
} BREthereumBCSCallbackLogType;
typedef void
(*BREthereumBCSCallbackLog) (BREthereumBCSCallbackContext context,
BREthereumBCSCallbackLogType event,
OwnershipGiven BREthereumLog log);
/**
* Save Blocks
*/
typedef void
(*BREthereumBCSCallbackSaveBlocks) (BREthereumBCSCallbackContext context,
OwnershipGiven BRArrayOf(BREthereumBlock) blocks);
/**
* Save Peers
*/
typedef void
(*BREthereumBCSCallbackSavePeers) (BREthereumBCSCallbackContext context,
OwnershipGiven BRArrayOf(BREthereumNodeConfig) peers);
/**
* Sync
*/
typedef enum {
BCS_CALLBACK_SYNC_STARTED,
BCS_CALLBACK_SYNC_UPDATE,
BCS_CALLBACK_SYNC_STOPPED
} BREthereumBCSCallbackSyncType;
typedef void
(*BREthereumBCSCallbackSync) (BREthereumBCSCallbackContext context,
BREthereumBCSCallbackSyncType event,
uint64_t blockNumberStart,
uint64_t blockNumberCurrent,
uint64_t blockNumberStop);
/**
* Get (Interesting) Blocks. Depending on the sync-mode we may ask the BRD endpoint for blocks
* that contain transactions or logs of interest.
*/
typedef void
(*BREthereumBCSCallbackGetBlocks) (BREthereumBCSCallbackContext context,
BREthereumAddress address,
BREthereumSyncInterestSet interests,
uint64_t blockStart,
uint64_t blockStop);
typedef struct {
BREthereumBCSCallbackContext context;
BREthereumBCSCallbackBlockchain blockChainCallback;
BREthereumBCSCallbackAccountState accountStateCallback;
BREthereumBCSCallbackTransaction transactionCallback;
BREthereumBCSCallbackLog logCallback;
BREthereumBCSCallbackSaveBlocks saveBlocksCallback;
BREthereumBCSCallbackSavePeers savePeersCallback;
BREthereumBCSCallbackSync syncCallback;
BREthereumBCSCallbackGetBlocks getBlocksCallback;
} BREthereumBCSListener;
/**
* Create BCS (a 'BlockChain Slice`) providing a view of the Ethereum blockchain for `network`
* focused on the `account` primary address. Initialize the synchronization with the previously
* saved `headers`. Provide `listener` to anounce BCS 'events'.
*
* @parameters
* @parameter headers - is this a BRArray; assume so for now.
*/
extern BREthereumBCS
bcsCreate (BREthereumNetwork network,
BREthereumAddress address,
BREthereumBCSListener listener,
BREthereumMode syncMode,
BRSetOf(BREthereumNodeConfig) peers,
BRSetOf(BREthereumBlock) blocks,
BRSetOf(BREthereumTransaction) transactions,
BRSetOf(BREthereumLog) logs);
extern void
bcsStart (BREthereumBCS bcs);
extern void
bcsStop (BREthereumBCS bcs);
extern BREthereumBoolean
bcsIsStarted (BREthereumBCS bcs);
extern void
bcsDestroy (BREthereumBCS bcs);
/**
* Scavenge BCS memory
*/
extern void
bcsClean (BREthereumBCS bcs);
/**
* Start a sync from block number. If a sync is in progress, then it is stopped. This function
* is typically invoked due to a) a User initiated re-sync, or b) the addition of a token - both
* invocations are through ewmSync().
*
* Any sync that is started with a range that contains an included transfer (transaction or log)
* will force transfer to 'pending'. Then, as the sync progresses, the transfer will, presumably,
* get re-included.
*
* @param bcs
* @param blockNumber the block number (>= 0) to sync from
*/
extern void
bcsSync (BREthereumBCS bcs,
uint64_t blockNumber);
extern BREthereumBoolean
bcsSyncInProgress (BREthereumBCS bcs);
/**
* Submit `transaction` to the Ethereum Network
*
* @param bcs
* @param transaction
*/
extern void
bcsSendTransaction (BREthereumBCS bcs,
BREthereumTransaction transaction);
/**
* Request the status of `transaction` for the given block from the Ethereum Network
*
* @param bcs
* @param transactionHash
* @param blockNumber
*@param blockTransactionIndex
*/
extern void
bcsSendTransactionRequest (BREthereumBCS bcs,
BREthereumHash transactionHash,
uint64_t blockNumber,
uint64_t blockTransactionIndex);
/**
* Request the status of `log` for the given block from the Ethereum Network
*
* @param bcs
* @param transactionHash
* @param blockNumber
* @param blockTransactionIndex
*/
extern void
bcsSendLogRequest (BREthereumBCS bcs,
BREthereumHash transactionHash,
uint64_t blockNumber,
uint64_t blockTransactionIndex);
extern void
bcsReportInterestingBlocks (BREthereumBCS bcs,
// interest
// request id
BRArrayOf(uint64_t) blockNumbers);
#ifdef __cplusplus
}
#endif
#endif /* BR_Ethereum_BCS_h */
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/P2P/PeerManager.h
|
<gh_stars>0
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_PEERMANAGER_H__
#define __ELASTOS_SDK_PEERMANAGER_H__
#include "Peer.h"
#include "TransactionPeerList.h"
#include "PublishedTransaction.h"
#include <Common/Lockable.h>
#include <WalletCore/BloomFilter.h>
#include <Plugin/Interface/IMerkleBlock.h>
#include <Plugin/Block/MerkleBlock.h>
#include <Plugin/Registry.h>
#include <string>
#include <vector>
#include <boost/weak_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/function.hpp>
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
#define PEER_MAX_CONNECTIONS 1
namespace Elastos {
namespace ElaWallet {
class Wallet;
class ChainParams;
typedef boost::shared_ptr<Wallet> WalletPtr;
typedef boost::shared_ptr<ChainParams> ChainParamsPtr;
typedef ElementSet<MerkleBlockPtr> BlockSet;
class PeerManager :
public Lockable,
public Peer::Listener {
public:
class Listener {
public:
Listener();
virtual ~Listener() {}
virtual void syncStarted() = 0;
virtual void syncProgress(uint32_t progress, time_t lastBlockTime, uint32_t bytesPerSecond, const std::string &downloadPeer) = 0;
virtual void syncStopped(const std::string &error) = 0;
virtual void txStatusUpdate() = 0;
virtual void saveBlocks(bool replace, const std::vector<MerkleBlockPtr> &blocks) = 0;
virtual void savePeers(bool replace, const std::vector<PeerInfo> &peers) = 0;
virtual void saveBlackPeer(const PeerInfo &peer) = 0;
virtual bool networkIsReachable() = 0;
virtual void txPublished(const std::string &hash, const nlohmann::json &result) = 0;
virtual void connectStatusChanged(const std::string &status) = 0;
};
public:
PeerManager(const ChainParamsPtr ¶ms,
const WalletPtr &wallet,
time_t earliestKeyTime,
uint32_t reconnectSeconds,
const std::vector<MerkleBlockPtr> &blocks,
const std::vector<PeerInfo> &peers,
const std::set<PeerInfo> &blackPeers,
const boost::shared_ptr<Listener> &listener,
const std::string &chainID,
const std::string &netType);
~PeerManager();
void SetWallet(const WalletPtr &wallet);
/**
* Connect to bitcoin peer-to-peer network (also call this whenever networkIsReachable()
* status changes)
*/
void Connect();
void AsyncConnect(const boost::system::error_code &error);
void ConnectLaster(time_t second);
void CancelTimer();
void ClearData();
/**
* Disconnect from bitcoin peer-to-peer network (may cause syncFailed(), saveBlocks() or
* savePeers() callbacks to fire)
*/
void Disconnect();
void Rescan();
uint32_t GetSyncStartHeight() const;
uint32_t GetEstimatedBlockHeight() const;
uint32_t GetLastBlockHeight() const;
uint32_t GetLastBlockTimestamp() const;
time_t GetKeepAliveTimestamp() const;
void SetKeepAliveTimestamp(time_t t);
double GetSyncProgress(uint32_t startHeight);
Peer::ConnectStatus GetConnectStatus() const;
bool SyncSucceeded() const;
void SetSyncSucceeded(bool succeeded);
void SetReconnectEnableStatus(bool status);
bool GetReconnectEnableStatus() const;
bool SetFixedPeer(const std::string &address, uint16_t port);
std::string GetCurrentPeerName() const;
std::string GetDownloadPeerName() const;
PeerPtr GetDownloadPeer() const;
size_t GetPeerCount() const;
void PublishTransaction(const TransactionPtr &transaction);
void PublishTransaction(const TransactionPtr &transaction, const Peer::PeerPubTxCallback &callback);
uint64_t GetRelayCount(const uint256 &txHash) const;
const std::string &GetChainID() const;
const std::vector<PeerInfo> &GetPeers() const;
void SetPeers(const std::vector<PeerInfo> &peers);
const std::string &GetID() const;
public:
virtual void OnConnected(const PeerPtr &peer);
virtual void OnDisconnected(const PeerPtr &peer, int error);
virtual void OnRelayedPeers(const PeerPtr &peer, const std::vector<PeerInfo> &peers);
virtual void OnRelayedTx(const PeerPtr &peer, const TransactionPtr &tx);
virtual void OnHasTx(const PeerPtr &peer, const uint256 &txHash);
virtual void OnRejectedTx(const PeerPtr &peer, const uint256 &txHash, uint8_t code, const std::string &reason);
virtual void OnRelayedBlock(const PeerPtr &peer, const MerkleBlockPtr &block);
virtual void OnRelayedPing(const PeerPtr &peer);
virtual void OnNotfound(const PeerPtr &peer, const std::vector<uint256> &txHashes,
const std::vector<uint256> &blockHashes);
virtual void OnSetFeePerKb(const PeerPtr &peer, uint64_t feePerKb);
virtual TransactionPtr OnRequestedTx(const PeerPtr &peer, const uint256 &txHash);
virtual bool OnNetworkIsReachable(const PeerPtr &peer);
virtual void OnThreadCleanup(const PeerPtr &peer);
private:
void InitBlocks(const std::vector<MerkleBlockPtr> &blocks);
void RemovePeer(const PeerPtr &peer);
Peer::ConnectStatus GetConnectStatusInternal() const;
private:
void FireSyncStarted();
void FireSyncProgress(double progress, const PeerPtr &peer, const MerkleBlockPtr &block);
void FireSyncStopped(int error);
void FireTxStatusUpdate();
void FireSaveBlocks(bool replace, const std::vector<MerkleBlockPtr> &blocks);
void FireSavePeers(bool replace, const std::vector<PeerInfo> &peers);
void FireSaveBlackPeer(const PeerInfo &peer);
bool FireNetworkIsReachable();
void FireTxPublished(const uint256 &hash, int code, const std::string &reason);
void FireConnectStatusChanged(Peer::ConnectStatus status);
void FireThreadCleanup();
int VerifyDifficulty(const ChainParamsPtr ¶ms, const MerkleBlockPtr &block,
const BlockSet &blockSet);
int VerifyDifficultyInner(const MerkleBlockPtr &block, const MerkleBlockPtr &previous,
uint32_t transitionTime, uint32_t targetTimeSpan, uint32_t targetTimePerBlock);
void LoadBloomFilter(const PeerPtr &peer);
void UpdateBloomFilter();
void FindPeers();
void SortPeers();
void SyncStopped();
void AddTxToPublishList(const TransactionPtr &tx, const Peer::PeerPubTxCallback &callback);
size_t PublishPendingTx(const PeerPtr &peer);
size_t
AddPeerToList(const PeerPtr &peer, const uint256 &txHash, std::vector<TransactionPeerList> &peerList);
bool
RemovePeerFromList(const PeerPtr &peer, const uint256 &txHash, std::vector<TransactionPeerList> &peerList);
void PeerMisbehaving(const PeerPtr &peer);
std::vector<uint128> AddressLookup(const std::string &hostname);
bool VerifyBlock(const MerkleBlockPtr &block, const MerkleBlockPtr &prev, const PeerPtr &peer);
std::vector<uint256> GetBlockLocators();
void LoadMempools();
void RequestUnrelayedTx(const PeerPtr &peer);
bool PeerListHasPeer(const std::vector<TransactionPeerList> &peerList, const uint256 &txhash,
const PeerPtr &peer);
size_t PeerListCount(const std::vector<TransactionPeerList> &list, const uint256 &txhash);
void UpdateAddressOnlyDone(const PeerPtr &peer, int success);
void LoadBloomFilterDone(const PeerPtr &peer, int success);
void UpdateFilterRerequestDone(const PeerPtr &peer, int success);
void UpdateFilterLoadDone(const PeerPtr &peer, int success);
void UpdateFilterPingDone(const PeerPtr &peer, int success);
void MempoolDone(const PeerPtr &peer, int success);
void RequestUnrelayedTxGetDataDone(const PeerPtr &peer, int success);
void PublishTxInvDone(const PeerPtr &peer, int success);
void FindPeersThreadRoutine(const std::string &hostname, uint64_t services);
void ReconnectLaster(time_t seconds);
double GetSyncProgressInternal(uint32_t startHeight);
private:
int _isConnected, _connectFailureCount, _misbehavinCount, _dnsThreadCount, _maxConnectCount;
bool _syncSucceeded, _enableReconnect;
Peer::ConnectStatus _connectStatus;
std::vector<PeerInfo> _peers;
std::set<PeerInfo> _blackPeers;
PeerInfo _fixedPeer;
std::vector<PeerPtr> _connectedPeers;
PeerPtr _downloadPeer;
mutable std::string _downloadPeerName;
time_t _keepAliveTimestamp, _earliestKeyTime;
uint32_t _reconnectSeconds, _syncStartHeight, _filterUpdateHeight, _estimatedHeight;
BloomFilterPtr _bloomFilter;
double _fpRate, _averageTxPerBlock;
BlockSet _blocks;
BlockSet _orphans;
BlockSet _checkpoints;
MerkleBlockPtr _lastBlock, _lastOrphan;
std::vector<TransactionPeerList> _txRelays, _txRequests;
std::vector<PublishedTransaction> _publishedTx;
std::vector<uint256> _publishedTxHashes;
std::string _chainID;
std::string _netType;
WalletPtr _wallet;
ChainParamsPtr _chainParams;
boost::asio::io_service _reconnectService;
boost::shared_ptr<boost::asio::deadline_timer> _reconnectTimer;
boost::weak_ptr<Listener> _listener;
};
typedef boost::shared_ptr<PeerManager> PeerManagerPtr;
}
}
#endif //__ELASTOS_SDK_PEERMANAGER_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
ThirdParty/breadwallet-core/ethereum/blockchain/BREthereumBlock.h
|
//
// BBREthereumBlock.h
// breadwallet-core Ethereum
//
// Created by <NAME> on 3/23/2018.
// Copyright © 2018 Breadwinner AG. All rights reserved.
//
// See the LICENSE file at the project root for license information.
// See the CONTRIBUTORS file at the project root for a list of contributors.
#ifndef BR_Ethereum_Block_H
#define BR_Ethereum_Block_H
#include <limits.h>
#include "ethereum/base/BREthereumBase.h"
#include "BREthereumTransaction.h"
#include "BREthereumLog.h"
#include "BREthereumAccountState.h"
#include "BREthereumBloomFilter.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* An Ethereum Block header.
*
* As per (2018-05-04 https://ethereum.github.io/yellowpaper/paper.pdf). [Documentation from
* that reference]. The header consists of: {hash, paretnHash, ommersHash, beneficiary, stateRoot,
* transactionRoot, receiptsRoot, logsBloom, difficulty, number, gasLimit, gasUsed, timestamp,
* extraData, mixHash, nonce}. Note: this nonce is not the account nonce but the 'mining nonce'.
*/
typedef struct BREthereumBlockHeaderRecord *BREthereumBlockHeader;
/**
* An Ethereum Block
*
* As per the Etheruem specification: The block in Ethereum consists of: { header, transacctions,
* and ommers/uncles}. To that we add: a block status - which is a complicated structure used
* during synchronization in order to gather all the needed, but intermediate, block state; the
* totalDifficulty - which is computed from checkpoints (in the worst case the generis block) by
* adding the difficulty of each individual block; and the next block - which provides the
* block chain through parents.
*/
typedef struct BREthereumBlockRecord *BREthereumBlock;
/**
* An Etheruem Proof of Work Struct holds intermediate state used in the Ethereum PoW algorithm
* used to validate blocks.
*/
typedef struct BREthereumProofOfWorkStruct *BREthereumProofOfWork;
/// MARK: - Block Header
//
// Block Header
//
extern void
blockHeaderRelease (BREthereumBlockHeader header);
/**
* Check if the block header is internally consistent
*
* @param header
* @return ETHEREUM_BOOLEAN_TRUE if valid
*/
extern BREthereumBoolean
blockHeaderIsInternallyValid (BREthereumBlockHeader header);
/**
* Check if the block header is valid. If `parent` is NULL, then `header` is consisder
* consistent (we'll check again at some point once we have the parent). If `pow` is provided
* then ProofOfWork is computed and used in validity.
*
* @note Section 4.3.3 'Block Header Validity in https://ethereum.github.io/yellowpaper/paper.pdf
*
* @param header
* @param parent
* @param parentOmmersCount
* @parem genesis
* @param pow
*
* @return ETHEREUM_BOOLEAN_TRUE if consistent
*/
extern BREthereumBoolean
blockHeaderIsValid (BREthereumBlockHeader header,
BREthereumBlockHeader parent,
size_t parentOmmersCount,
BREthereumBlockHeader genesis,
BREthereumProofOfWork pow);
extern BREthereumBlockHeader
blockHeaderRlpDecode (BRRlpItem item,
BREthereumRlpType type,
BRRlpCoder coder);
extern BRRlpItem
blockHeaderRlpEncode (BREthereumBlockHeader header,
BREthereumBoolean withNonce,
BREthereumRlpType type,
BRRlpCoder coder);
extern BREthereumHash
blockHeaderGetHash (BREthereumBlockHeader header);
extern uint64_t
blockHeaderGetNumber (BREthereumBlockHeader header);
extern UInt256
blockHeaderGetDifficulty (BREthereumBlockHeader header);
extern uint64_t
blockHeaderGetGasUsed (BREthereumBlockHeader header);
extern uint64_t
blockHeaderGetTimestamp (BREthereumBlockHeader header);
extern BREthereumHash
blockHeaderGetParentHash (BREthereumBlockHeader header);
extern BREthereumHash
blockHeaderGetMixHash (BREthereumBlockHeader header);
extern BREthereumBoolean
blockHeaderIsCHTRoot (BREthereumBlockHeader header);
// ...
extern uint64_t
blockHeaderGetNonce (BREthereumBlockHeader header);
extern BREthereumBoolean
blockHeaderMatch (BREthereumBlockHeader header,
BREthereumBloomFilter filter);
extern BREthereumBoolean
blockHeaderMatchAddress (BREthereumBlockHeader header,
BREthereumAddress address);
// Support BRSet
extern size_t
blockHeaderHashValue (const void *h);
// Support BRSet
extern int
blockHeaderHashEqual (const void *h1, const void *h2);
extern void
blockHeaderReleaseForSet (void *ignore, void *item);
// Support sorting
extern BREthereumComparison
blockHeaderCompare (BREthereumBlockHeader h1,
BREthereumBlockHeader h2);
extern BREthereumBlockHeader
blockHeaderCopy (BREthereumBlockHeader source);
extern void
blockHeadersRelease (BRArrayOf(BREthereumBlockHeader) headers);
/// MARK: - CHT Root (Number)
/**
* From Parity:
* " Get the nth CHT root, if it's been computed.
*
* CHT root 0 is from block `1..2048`.
* CHT root 1 is from block `2049..4096`
* and so on.
*
* This is because it's assumed that the genesis hash is known,
* so including it within a CHT would be redundant."
*/
extern uint64_t
blockHeaderGetCHTRootNumber (BREthereumBlockHeader header);
extern uint64_t
chtRootNumberGetFromNumber (uint64_t number);
#define BLOCK_HEADER_CHT_ROOT_INTERVAL (2048)
#define BLOCK_HEADER_CHT_ROOT_INTERVAL_SHIFT (11) // 2048 == (1 << 11)
/// MARK: - Block
//
// Block
//
extern BREthereumBlock
blockCreateMinimal(BREthereumHash hash,
uint64_t number,
uint64_t timestamp,
UInt256 difficulty);
extern BREthereumBlock
blockCreateFull (BREthereumBlockHeader header,
BREthereumBlockHeader ommers[], size_t ommersCount,
BREthereumTransaction transactions[], size_t transactionCount);
extern BREthereumBlock
blockCreate (BREthereumBlockHeader header);
extern void
blockUpdateBody (BREthereumBlock block,
BRArrayOf(BREthereumBlockHeader) ommers,
BRArrayOf(BREthereumTransaction) transactions);
extern void
blockRelease (BREthereumBlock block);
extern BREthereumBlockHeader
blockGetHeader (BREthereumBlock block);
extern unsigned long
blockGetTransactionsCount (BREthereumBlock block);
extern BREthereumTransaction
blockGetTransaction (BREthereumBlock block, size_t index);
extern BREthereumBoolean
blockTransactionsAreValid (BREthereumBlock block);
extern unsigned long
blockGetOmmersCount (BREthereumBlock block);
extern BREthereumBlockHeader
blockGetOmmer (BREthereumBlock block, unsigned int index);
extern BREthereumHash
blockGetHash (BREthereumBlock block);
extern uint64_t
blockGetNumber (BREthereumBlock block);
extern uint64_t
blockGetConfirmations (BREthereumBlock block);
extern uint64_t
blockGetTimestamp (BREthereumBlock block);
extern UInt256
blockGetDifficulty (BREthereumBlock block);
/*!
* The total difficulty is computed as an emergent property of the entire chain by summing up
* the difficulty for each block. That implies, as of 2018, >6,000,000 block to sum. However,
* if we can rely on checkpoints (blocks with a pre-computed totalDifficulty) then we only
* need to sum back to the checkpoint - but still need all the blocks to the checkpoint.
*
* Additionally, both Parity and Geth support a 'header proof' which provides the total difficulty.
*/
extern UInt256
blockGetTotalDifficulty (BREthereumBlock block);
extern void
blockSetTotalDifficulty (BREthereumBlock block,
UInt256 totalDifficulty);
extern void
blockClrTotalDifficulty (BREthereumBlock block);
extern BREthereumBoolean
blockHasTotalDifficulty (BREthereumBlock block);
/**
* Update the totalDifficulty for `block` by recusively updating the totalDifficutly for
* block->next until block->next is NULL or block->next already has a totalDifficulty.
*
* Note: this is not a tail recursive algorithm and may overflow stack memory. In practice we
* never have block chains more than several thousand (and would never be updating the entire
* chain all at once anyways) and thus *will* be okay.
*/
extern UInt256
blockRecursivelyPropagateTotalDifficulty (BREthereumBlock block);
/**
* A block is valid if and only if it has a total difficulty.
*
* @param block the block
*
* @return true if valid; false otherwise.
*/
static inline BREthereumBoolean
blockIsValid (BREthereumBlock block) {
return blockHasTotalDifficulty (block);
}
extern void
blockLinkLogsWithTransactions (BREthereumBlock block);
extern BRRlpItem
blockRlpEncode (BREthereumBlock block,
BREthereumNetwork network,
BREthereumRlpType type,
BRRlpCoder coder);
extern BREthereumBlock
blockRlpDecode (BRRlpItem item,
BREthereumNetwork network,
BREthereumRlpType type,
BRRlpCoder coder);
// Support BRSet
extern size_t
blockHashValue (const void *h);
// Support BRSet
extern int
blockHashEqual (const void *h1, const void *h2);
extern void
blockReleaseForSet (void *ignore, void *item);
extern void
blocksRelease (OwnershipGiven BRArrayOf(BREthereumBlock) blocks);
/// MARK: - Block Next (Chaining)
#define BLOCK_NEXT_NONE ((BREthereumBlock) 0)
extern BREthereumBlock
blockGetNext (BREthereumBlock block);
extern BREthereumBlock // old 'next'
blockSetNext (BREthereumBlock block,
BREthereumBlock next);
extern BREthereumBoolean
blockHasNext (BREthereumBlock block);
static inline BREthereumBlock // old 'next'
blockClrNext (BREthereumBlock block) {
return blockSetNext(block, BLOCK_NEXT_NONE);
}
/// MARK: - Block Body Pair
/**
* A Block Body Pair ...
*/
typedef struct {
BRArrayOf(BREthereumTransaction) transactions;
BRArrayOf(BREthereumBlockHeader) uncles;
} BREthereumBlockBodyPair;
extern void
blockBodyPairRelease (BREthereumBlockBodyPair *pair);
extern void
blockBodyPairsRelease (BRArrayOf(BREthereumBlockBodyPair) pairs);
/// MARK: - Block Header Proof
typedef struct {
BREthereumHash hash;
UInt256 totalDifficulty;
} BREthereumBlockHeaderProof;
/// MARK: - Block Status
typedef enum {
BLOCK_REQUEST_NOT_NEEDED,
BLOCK_REQUEST_PENDING,
BLOCK_REQUEST_COMPLETE,
BLOCK_REQUEST_ERROR
} BREthereumBlockRequestState;
typedef struct {
BREthereumHash hash;
BREthereumBlockRequestState transactionRequest;
BRArrayOf (BREthereumTransaction) transactions;
BRArrayOf (BREthereumGas) gasUsed;
BREthereumBlockRequestState logRequest;
BRArrayOf(BREthereumLog) logs;
BREthereumBlockRequestState accountStateRequest;
BREthereumAccountState accountState;
BREthereumBlockRequestState headerProofRequest;
BREthereumBlockHeaderProof headerProof;
BREthereumBoolean error;
} BREthereumBlockStatus;
/**
* Get the block's status
*/
extern BREthereumBlockStatus
blockGetStatus (BREthereumBlock block);
extern BREthereumBoolean
blockHasStatusComplete (BREthereumBlock block);
extern BREthereumBoolean
blockHasStatusError (BREthereumBlock block);
extern void
blockReportStatusError (BREthereumBlock block,
BREthereumBoolean error);
//
// Transaction Request
//
extern BREthereumBoolean
blockHasStatusTransactionsRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
extern void
blockReportStatusTransactionsRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
/**
* Set the transactions in the block's status. The transactions are
* BRArrayOf(BREthereumTransaction) and the transactions are stolen (the array is now owned
* by `block`; the transactions are owned by another).
*/
extern void
blockReportStatusTransactions (BREthereumBlock block,
OwnershipGiven BRArrayOf(BREthereumTransaction) transactions);
extern void
blockReportStatusGasUsed (BREthereumBlock block,
BRArrayOf(BREthereumGas) gasUsed);
//
// Log Request
//
extern BREthereumBoolean
blockHasStatusLogsRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
extern void
blockReportStatusLogsRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
/**
* Set the logs in the block's status. Handling of `logs` is identical to handling of
* `transactions` - see above
*/
extern void
blockReportStatusLogs (BREthereumBlock block,
OwnershipGiven BRArrayOf(BREthereumLog) log);
//
// Account State Reqeust
//
extern BREthereumBoolean
blockHasStatusAccountStateRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
extern void
blockReportStatusAccountStateRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
/**
* Set the account state in the block's status.
*/
extern void
blockReportStatusAccountState (BREthereumBlock block,
BREthereumAccountState accountState);
//
// Header Proof Request
//
extern BREthereumBoolean
blockHasStatusHeaderProofRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
extern void
blockReportStatusHeaderProofRequest (BREthereumBlock block,
BREthereumBlockRequestState request);
extern void
blockReportStatusHeaderProof (BREthereumBlock block,
BREthereumBlockHeaderProof proof);
//
//
//
extern BREthereumBoolean
blockHasStatusTransaction (BREthereumBlock block,
BREthereumTransaction transaction);
extern BREthereumBoolean
blockHasStatusLog (BREthereumBlock block,
BREthereumLog log);
extern void
blockReleaseStatus (BREthereumBlock block,
BREthereumBoolean releaseTransactions,
BREthereumBoolean releaseLogs);
/// MARK: - Block Decoding for LES
/**
* Return BRArrayOf(BREthereumBlockHeader) w/ array owned by caller.
*/
extern BRArrayOf(BREthereumBlockHeader)
blockOmmersRlpDecode (BRRlpItem item,
BREthereumNetwork network,
BREthereumRlpType type,
BRRlpCoder coder);
/**
* Return BRArrayOf(BREthereumTransaction) w/ array owned by caller
*/
extern BRArrayOf(BREthereumTransaction)
blockTransactionsRlpDecode (BRRlpItem item,
BREthereumNetwork network,
BREthereumRlpType type,
BRRlpCoder coder);
/// MARK: - Genesis Blocks
/**
* Return a newly-allocaed block header duplicating the genesis block header for `network`.
*/
extern BREthereumBlockHeader
networkGetGenesisBlockHeader (BREthereumNetwork network);
/**
* Returh a newly-allocated block duplicating the generic block's header for `network`.
*/
extern BREthereumBlock
networkGetGenesisBlock (BREthereumNetwork network);
/// MARK: - Block Checkpoint
/**
* A Block Checkpoint ...
*/
typedef struct {
uint64_t number;
BREthereumHash hash;
union {
char *std;
UInt256 td;
} u;
uint64_t timestamp;
} BREthereumBlockCheckpoint;
#define BLOCK_CHECKPOINT_LAST_NUMBER (UINT64_MAX)
#define BLOCK_CHECKPOINT_LAST_TIMESTAMP (UINT64_MAX)
extern const BREthereumBlockCheckpoint *
blockCheckpointLookupLatest (BREthereumNetwork network);
extern const BREthereumBlockCheckpoint *
blockCheckpointLookupByNumber (BREthereumNetwork network,
uint64_t number);
extern const BREthereumBlockCheckpoint *
blockCheckpointLookupByTimestamp (BREthereumNetwork network,
uint64_t timestamp);
extern BREthereumBlockHeader
blockCheckpointCreatePartialBlockHeader (const BREthereumBlockCheckpoint *checkpoint);
//
// Private
//
private_extern void
blockFree (BREthereumBlock block);
/// MARK: - Proof of Work
extern BREthereumProofOfWork
proofOfWorkCreate (void);
extern void
proofOfWorkRelease (BREthereumProofOfWork pow);
extern void
proofOfWorkGenerate (BREthereumProofOfWork pow,
BREthereumBlockHeader header);
extern void
proofOfWorkCompute (BREthereumProofOfWork pow,
BREthereumBlockHeader header,
UInt256 *n,
BREthereumHash *m);
#ifdef __cplusplus
}
#endif
#endif /* BR_Ethereum_Block_H */
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Wallet/UTXO.h
|
<reponame>fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_UTXO_H__
#define __ELASTOS_SDK_UTXO_H__
#include <Common/uint256.h>
#include <Plugin/Transaction/TransactionOutput.h>
#include <vector>
namespace Elastos {
namespace ElaWallet {
class TransactionInput;
class BigInt;
typedef boost::shared_ptr<TransactionInput> InputPtr;
class UTXO {
public:
UTXO();
UTXO(const UTXO &u);
UTXO &operator=(const UTXO &u);
UTXO(const uint256 &hash, uint16_t i, time_t t = 0, uint32_t h = 0, const OutputPtr &o = nullptr);
UTXO(const InputPtr &input);
virtual ~UTXO();
bool operator==(const UTXO &u) const;
const uint256 &Hash() const;
void SetHash(const uint256 &hash);
const uint16_t &Index() const;
void SetIndex(uint16_t index);
time_t Timestamp() const;
void SetTimestamp(time_t t);
uint32_t BlockHeight() const;
void SetBlockHeight(uint32_t h);
const OutputPtr &Output() const;
void SetOutput(const OutputPtr &o);
uint32_t GetConfirms(uint32_t lastBlockHeight) const;
bool Equal(const InputPtr &input) const;
bool Equal(const uint256 &hash, uint16_t index) const;
protected:
time_t _timestamp;
uint32_t _blockHeight;
OutputPtr _output;
uint256 _hash;
uint16_t _n;
};
typedef boost::shared_ptr<UTXO> UTXOPtr;
typedef std::vector<UTXOPtr> UTXOArray;
typedef struct {
bool operator() (const UTXOPtr &x, const UTXOPtr &y) const {
if (x->Hash() == y->Hash()) {
return x->Index() < y->Index();
} else {
return x->Hash() < y->Hash();
}
}
} UTXOCompare;
typedef std::set<UTXOPtr, UTXOCompare> UTXOSet;
}
}
#endif //__ELASTOS_SDK_UTXO_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Plugin/Transaction/Payload/UnregisterCR.h
|
<filename>SDK/Plugin/Transaction/Payload/UnregisterCR.h
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef __ELASTOS_SDK_UNREGISTERCR_H__
#define __ELASTOS_SDK_UNREGISTERCR_H__
#include <Plugin/Transaction/Payload/IPayload.h>
namespace Elastos {
namespace ElaWallet {
class UnregisterCR : public IPayload {
public:
UnregisterCR();
~UnregisterCR();
void SetCID(const uint168 &cid);
const uint168 &GetCID() const;
void SetSignature(const bytes_t &signature);
const bytes_t &GetSignature() const;
virtual size_t EstimateSize(uint8_t version) const;
virtual void Serialize(ByteStream &ostream, uint8_t version) const;
virtual bool Deserialize(const ByteStream &istream, uint8_t version);
void SerializeUnsigned(ByteStream &ostream, uint8_t version) const;
bool DeserializeUnsigned(const ByteStream &istream, uint8_t version);
virtual nlohmann::json ToJson(uint8_t version) const;
virtual void FromJson(const nlohmann::json &j, uint8_t version);
virtual IPayload &operator=(const IPayload &payload);
UnregisterCR &operator=(const UnregisterCR &payload);
private:
uint168 _cid;
bytes_t _signature;
};
}
}
#endif //__ELASTOS_SDK_UNREGISTERCR_H__
|
fakecoinbase/elastosslashElastos.ELA.SPV.Cpp
|
SDK/Database/DIDDataStore.h
|
/*
* Copyright (c) 2019 Elastos Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef __ELASTOS_SDK_DIDDATASTORE_H__
#define __ELASTOS_SDK_DIDDATASTORE_H__
#include "Sqlite.h"
#include "TableBase.h"
#include <Common/uint256.h>
namespace Elastos {
namespace ElaWallet {
class DIDDataStore : public TableBase {
public:
DIDDataStore(Sqlite *sqlite, SqliteTransactionType type = IMMEDIATE);
~DIDDataStore();
virtual void InitializeTable();
private:
const std::string DID_OLD_TABLE_NAME = "didTable";
const std::string DID_TABLE_NAME = "didNewdTable";
const std::string DID_COLUMN_ID = "_id";
const std::string DID_PAYLOAD_BUFF = "didBuff";
const std::string DID_CREATE_TIME = "createTime";
const std::string BLOCK_HEIGHT = "blockHeight";
const std::string TIME_STAMP = "timeStamp";
const std::string TX_HASH = "txHash";
const std::string DID_RESERVE = "reserve";
const std::string DID_DATABASE_CREATE = "create table if not exists " + DID_TABLE_NAME + " (" +
DID_COLUMN_ID + " text not null, " +
DID_PAYLOAD_BUFF + " blob, " +
DID_CREATE_TIME + " integer, " +
BLOCK_HEIGHT + " integer, " +
TIME_STAMP + " integer, " +
TX_HASH + " text DEFAULT '', " +
DID_RESERVE + " text DEFAULT 'ELA');";
};
}
}
#endif //__ELASTOS_SDK_DIDDATASTORE_H__
|
hsswx7/CS4500GroupProject
|
RiverTracer/RiverTracerSource/justFiles/RGBpixmap.h
|
<filename>RiverTracer/RiverTracerSource/justFiles/RGBpixmap.h
#ifndef _RGBPIXMAP
#define _RGBPIXMAP
#include <string>
#include <iostream>
#include <fstream>
#include <strstream>
#include <gl/glut.h>
using namespace std;
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
//$$$$$$$$$$$$$$$$$$$ class IntPoint $$$$$$$$$$$$$$
class IntPoint{
public:
int x, y;
IntPoint(){ x = y = 0;}
IntPoint(int xx, int yy){ x = xx; y = yy;} // constructor
void set(int xx, int yy){x = xx; y = yy;}
void set(IntPoint p) {x = p.x; y = p.y;}
};
//$$$$$$$$$$$$ class IntRect $$$$$$$$$$$
class IntRect{
public:
int left, top, right, bott;
void set(int ll, int tt, int rr, int bb){left = ll; top = tt; right = rr; bott = bb;}
void set(IntRect r){left = r.left;top = r.top; right = r.right; bott = r.bott;}
void print()
{
cout << "IntRect: " << left << " " << top << " " << right << " " << bott << endl;
int nCols = right - left;
int nBytes = 3 * nCols;
int nBytesInRow = ((nBytes + 3)/4)*4;
int numPadBytes = nBytesInRow - nBytes;
cout << " nCols, # pad bytes = " << nCols << "," <<numPadBytes << endl;
}
void fix()
{ // reestablish order of left, right, etc.
if(left > right){ int tmp = left; left = right; right = tmp;} //swap
if(bott > top){ int temp = top; top = bott; bott = temp;}
}
//<<<<<<<<<<<<<<<<<<<<<<<<< drawRubber >>>>>>>>>>>
void draw() // draw rectangle
{
glBegin(GL_LINE_LOOP);
glVertex2i(left, top); glVertex2i(right,top);
glVertex2i(right,bott); glVertex2i(left, bott);
glEnd();
glFlush();
}
void drawDiag() // draw diagonal of rect (for rubber line)
{
glBegin(GL_LINES);
glVertex2i(left,top);
glVertex2i(right, bott);
glEnd();
}
}; // end of IntRect
//$$$$$$$$$$$$$$$$$$ class mRGB $$$$$$$$$$$$$$$$$$
class mRGB{ // the name RGB is reserved in windows
public: uchar r,g,b;
mRGB(){r = g = b = 0;}
mRGB(mRGB& p){r = p.r; g = p.g; b = p.b;}
mRGB(uchar rr, uchar gg, uchar bb){r = rr; g = gg; b = bb;}
void set(uchar rr, uchar gg, uchar bb){r = rr; g = gg; b = bb;}
};
//$$$$$$$$$$$$$$$$$ RGBPixmap $$$$$$$$$$$$$$$
class RGBpixmap{
private:
mRGB* pixel; // array of pixels
public:
int nRows, nCols; // dimensions of the pixmap
RGBpixmap() {nRows = nCols = 0; pixel = 0;}
RGBpixmap(int rows, int cols) //constructor
{
nRows = rows;
nCols = cols;
pixel = new mRGB[rows*cols];
}
int readBMPFile(string fname); // read BMP file into this pixmap
void setTexture(GLuint textureName);
void makeCheckerboard();
int writeBMPFile(string fname); // write this pixmap to a BMP file
void freeIt() // give back memory for this pixmap
{
delete []pixel;
nRows = nCols = 0;
}
//<<<<<<<<<<<<<<<<<< copy >>>>>>>>>>>>>>>>>>>
void copy(IntPoint from, IntPoint to, int x, int y, int width, int height)
{ // copy a region of the display back onto the display
if(nRows == 0 || nCols == 0) return;
glCopyPixels(x, y, width, height,GL_COLOR);
}
//<<<<<<<<<<<<<<<<<<< draw >>>>>>>>>>>>>>>>>
void draw()
{ // draw this pixmap at current raster position
if(nRows == 0 || nCols == 0) return;
//tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glDrawPixels(nCols, nRows,GL_RGB, GL_UNSIGNED_BYTE,pixel);
}
//<<<<<<<<<<<<<<<<< read >>>>>>>>>>>>>>>>
int read(int x, int y, int wid, int ht)
{ // read a rectangle of pixels into this pixmap
nRows = ht;
nCols = wid;
pixel = new mRGB[nRows *nCols]; if(!pixel) return -1;
//tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(x, y, nCols, nRows, GL_RGB,GL_UNSIGNED_BYTE,pixel);
return 0;
}
//<<<<<<<<<<<<<<<<< read from IntRect >>>>>>>>>>>>>>>>
int read(IntRect r)
{ // read a rectangle of pixels into this pixmap
nRows = r.top - r.bott;
nCols = r.right - r.left;
pixel = new mRGB[nRows *nCols]; if(!pixel) return -1;
//tell OpenGL NOT to try to align pixels to 4 byte boundaries in memory
glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(r.left,r.bott, nCols, nRows, GL_RGB,GL_UNSIGNED_BYTE,pixel);
return 0;
}
//<<<<<<<<<<<<<< setPixel >>>>>>>>>>>>>
void setPixel(int x, int y, mRGB color)
{
if(x>=0 && x <nCols && y >=0 && y < nRows)
pixel[nCols * y + x] = color;
}
//<<<<<<<<<<<<<<<< getPixel >>>>>>>>>>>
mRGB getPixel(int x, int y)
{
mRGB bad(255,255,255);
if(x < 0 || x >= nCols || y < 0 || y >= nRows)
{
cout << "\nx,y = " << x << "," << y << " bad in getPixel()";
return bad;
}
return pixel[nCols * y + x];
}
};
fstream inf; // global in this file for convenience
fstream outf; // ditto
//<<<<<<<<<<<<<<<<<<<<< putShort >>>>>>>>>>>>>>>>>>>>
void putShort(ushort i)
{ // write short in little-endian form
outf.put((char)(i & 0xff));
outf.put((char)((i >> 8) & 0xff));
}
//<<<<<<<<<<<<<<<<<<<<< putLong >>>>>>>>>>>>>>>>>>>>
void putLong(ulong i)
{ // write long in little-endian form
outf.put((char)(i & 0xff));
outf.put((char)((i >> 8) & 0xff));
outf.put((char)((i >> 16) & 0xff));
outf.put((char)((i >> 24) & 0xff));
}
//<<<<<<<<<<<<<<<<<<<<< getShort >>>>>>>>>>>>>>>>>>>>
ushort getShort()
{// read a short in little-endian form
char ic;
ushort ip;
inf.get(ic); ip = ic; //first byte is little one
inf.get(ic); ip |= ((ushort)ic << 8); // or in high order byte
return ip;
}
//<<<<<<<<<<<<<<<<<<<< getLong >>>>>>>>>>>>>>>>>>>
ulong getLong()
{ // get little-endian 4-byte value from file, compose along portably
ulong ip = 0;
char ic = 0;
unsigned char uc = ic;
inf.get(ic); uc = ic; ip = uc;
inf.get(ic); uc = ic; ip |=((ulong)uc << 8);
inf.get(ic); uc = ic; ip |=((ulong)uc << 16);
inf.get(ic); uc = ic; ip |=((ulong)uc << 24);
return ip;
}
//ah added
void RGBpixmap::setTexture(GLuint textureName)
{
glBindTexture(GL_TEXTURE_2D,textureName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,nCols,nRows,0,GL_RGB,GL_UNSIGNED_BYTE,pixel);
}
// makeCheckerboard
void RGBpixmap :: makeCheckerboard()
{
nRows = nCols = 64;
pixel = new mRGB[3 * nRows * nCols];
if (!pixel) {cout << "out of memory!";return;}
long count = 0;
for (int i = 0; i < nRows; i++)
for (int j = 0; j < nCols; j++)
{
if(((i/8) + (j/8)) % 2 == 0)
{
pixel[count].r = 0; //red
pixel[count].g = 255; //green
pixel[count++].b = 127; //blue
} else {
pixel[count].r = 255; //red
pixel[count].g = 69; //green
pixel[count++].b = 0; //blue
}
}
}
//<<<<<<<<<<<<<<<<<< RGBPixmap:: readBmpFile>>>>>>>>>>>>>
int RGBpixmap:: readBMPFile(string fname)
{ // Read into memory an mRGB image from an uncompressed BMP file.
// return 0 on failure, 1 on success
inf.open(fname.c_str(), ios::in|ios::binary); //must read raw binary char's.
if(!inf){ cout << " can't open file: " << fname << endl; return 0;}
int k, row, col, numPadBytes, nBytesInRow;
// read header information
char ch1, ch2;
inf.get(ch1); inf.get(ch2); // type is always 'BM'
//cout << "file type = " << ch1 << ch2 << endl;
ulong fileSize = getLong();
ushort reserved1 = getShort(); // always 0
ushort reserved2= getShort(); // always 0
ulong offBits = getLong(); // offset to image - unreliable
ulong headerSize = getLong(); // always 40
ulong numCols = getLong(); // number of columns in image
ulong numRows = getLong(); // number of rows in image
ushort planes= getShort(); // always 1
ushort bitsPerPix = getShort(); // 8 or 24;only 24 bit case done
ulong compression = getLong(); // must be 0 for umcompressed
ulong imageSize = getLong(); // total bytes in image
ulong xPels = getLong(); // always 0
ulong yPels = getLong(); // always 0
ulong numLUTentries = getLong(); // 256 for 8 bit, otherwise 0
ulong impColors = getLong(); // always 0
if(bitsPerPix != 24) {cout << "not a 24 bit/pixelimage!\n"; inf.close(); return 0;}; // error!
// in BMP file, pad bytes inserted at end of each row so total number is a mult. of 4
nBytesInRow = ((3 * numCols + 3)/4) * 4; // round up 3*numCols to next mult. of 4
numPadBytes = nBytesInRow - 3 * numCols; // need this many
nRows = numRows; // set class's data members
nCols = numCols;
cout << "numRows,numCols = " << numRows << "," << numCols << endl;
cout.flush();
pixel = new mRGB[nRows * nCols]; //space for array in memory
if(!pixel) return 0; // out of memory!
long count = 0;
char dum,r,g,b;
for(row = 0; row < nRows; row++) // read pixel values
{
for(col = 0; col < nCols; col++)
{
inf.get(b); inf.get(g); inf.get(r); // funny color order in BMP file
pixel[count].r = r; pixel[count].g = g; pixel[count++].b = b;
}
for(k = 0; k < numPadBytes ; k++) //skip over padding bytes at row's end
inf >> dum;
}
inf.close();
return 1; // success
}
//<<<<<<<<<<<<<<<<<< RGBpixmap:: writeBMPFile >>>>>>>>>>>>>>>>>
int RGBpixmap::writeBMPFile(string fname)
{
outf.open(fname.c_str(), ios::out | ios::binary);
if( !outf){ cout << " can't open file!\n"; return 0;}
if((nRows <= 0) || (nCols <= 0)){cout << "\n degenerate image!\n"; return 0;}
// Must write a multiple of four bytes in each row of the image
ushort nBytesInRow = ((3 * nCols + 3)/4) * 4; // round up 3 * nCols to next mult. of 4
int numPadBytes = nBytesInRow - 3 * nCols; // num of pad bytes at end of each row
ulong biSizeImage = nBytesInRow * (ulong)nRows; // size of image
//write pixmap FileHeader
ushort bfType = 0x4d42; // 'BM';'B'=0x42, 'M'=0x4d
putShort(bfType); // write it to file
ulong bfSize = 54 + biSizeImage; //total size of image
putLong(bfSize);
putShort(0); putShort(0);// reserved 1 & 2
putLong(ulong(54)); //bfOffBits: 54 - but not used in readers
putLong(ulong(40)); // biSize - bytes in info header
putLong(ulong(nCols)); putLong(ulong(nRows));
putShort(ushort(1)); putShort(ushort(24)); // bit planes & bit count
putLong(0L); // compression
putLong(biSizeImage);
putLong(0L); putLong(0L);//pelsPerMeterX and Y
putLong(0L); putLong(0);//colors used & important colors
//##############write bytes ###############################
long count = 0;
for(int row = 0; row < nRows; row++)
{
for(int col = 0; col < nCols; col++)
{
outf.put(pixel[count].b);
outf.put(pixel[count].g);
outf.put(pixel[count++].r);
}
//now pad this row so num bytes is a mult of 4
for(int k = 0; k < numPadBytes ; k++) //write dummy bytes to pad out row
outf.put(char(0)); //padding bytes of 0
}
outf.close();
return 1; //success
}
#endif
|
zachbateman/evogression
|
evogression/calc_target_c.c
|
#include <Python.h>
#include <math.h>
#include <stdio.h>
// See: https://www.tutorialspoint.com/python/python_further_extensions.htm
static PyObject* calc_target_c(PyObject *self, PyObject *args) {
// arg is form (dict parameters, dict modifiers)
double T = 0; // bogus value for first layer
double inner_T = 0;
PyObject *parameters, *modifiers;
if (!PyArg_ParseTuple(args, "OO", ¶meters, &modifiers)) {
return NULL;
}
PyObject *layer_name, *layer_modifiers;
Py_ssize_t pos = 0;
double C, B, Z;
double X;
PyObject *coeffs;
PyObject *param;
PyObject *param_value;
Py_ssize_t pos2;
PyObject *T_str = Py_BuildValue("s", "T");
PyObject *N_str = Py_BuildValue("s", "N");
const double big_num = pow(10, 150);
// DEPENDING ON ORDERED DICTIONARY HERE!!!
while (PyDict_Next(modifiers, &pos, &layer_name, &layer_modifiers)) {
inner_T = 0;
pos2 = 0;
// while (PyDict_Next(parameters, &pos2, ¶m, ¶m_value)) {
// if (PyDict_Contains(layer_modifiers, param)) {
// PyArg_ParseTuple(PyDict_GetItem(layer_modifiers, param), "dddd", &C, &B, &Z, &X);
// switch ((int) X) { // switching for faster evaluation where possible
// case 0:
// inner_T += 1;
// case 1:
// inner_T += C * (B * PyFloat_AsDouble(param_value) + Z);
// default:
// inner_T += pow(C * (B * PyFloat_AsDouble(param_value) + Z), X);
// }
// }
// }
// if (T != 0) { // assuming T will ONLY be zero on first run through loop... checking against zero should be faster?
// PyArg_ParseTuple(PyDict_GetItem(layer_modifiers, T_str), "dddd", &C, &B, &Z, &X);
// switch ((int) X) { // switching for faster evaluation where possible
// case 0:
// inner_T += 1;
// case 1:
// inner_T += C * (B * T + Z);
// default:
// inner_T += pow(C * (B * T + Z), X);
// }
// }
// T = inner_T + PyFloat_AsDouble(PyDict_GetItem(layer_modifiers, N_str));
while (PyDict_Next(layer_modifiers, &pos2, ¶m, &coeffs)) {
if (param == N_str) {
inner_T += PyFloat_AsDouble(coeffs);
} else if (param == T_str) {
PyArg_ParseTuple(coeffs, "dddd", &C, &B, &Z, &X);
switch ((int) X) { // switching for faster evaluation where possible
case 0:
inner_T += 1;
case 1:
inner_T += C * (B * T + Z);
default:
inner_T += pow(C * (B * T + Z), X);
}
} else {
PyArg_ParseTuple(coeffs, "dddd", &C, &B, &Z, &X);
switch ((int) X) { // switching for faster evaluation where possible
case 0:
inner_T += 1;
case 1:
inner_T += C * (B * PyFloat_AsDouble(PyDict_GetItem(parameters, param)) + Z);
default:
inner_T += pow(C * (B * PyFloat_AsDouble(PyDict_GetItem(parameters, param)) + Z), X);
}
}
}
T = inner_T;
}
if (T > big_num) {
printf("Value of T: %f\n", T);
printf("Value of inner_T: %f\n", inner_T);
PyErr_SetString(PyExc_OverflowError, "Overflow... T got too big! (?)"); // really big number should make this creature die if crazy bad calculations (overflow)
return NULL;
}
return Py_BuildValue("d", T); // "d" instructs to build a Python double/float
}
static PyMethodDef methods[] = {
{"calc_target_c", &calc_target_c, METH_VARARGS, "C version of calc_target"},
{NULL, NULL, 0, NULL}
};
// See: http://python3porting.com/cextensions.html
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"calc_target_c", /* m_name */
"C version of calc_target", /* m_doc */
-1, /* m_size */
methods, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
static PyObject *moduleinit(void) {
PyObject *m;
m = PyModule_Create(&moduledef);
return m;
}
PyMODINIT_FUNC PyInit_calc_target_c(void) {
return moduleinit();
}
|
apologist/console_calculator
|
console_calculator/calculator.h
|
<reponame>apologist/console_calculator
#pragma once
#include <string>
#include <list>
#include <map>
#include <regex>
#include <stack>
#include <vector>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <iomanip>
using namespace std;
#pragma region Const
#ifdef _WIN32
#define NEWLINE "\r\n"
#elif defined macintosh
#define NEWLINE "\r"
#else
#define NEWLINE "\n"
#endif
const char signs_m[] = {'+', '-', '*', '/'};
const string VARIABLE_KEY_WORD = "var";
const vector<char> signs(signs_m, signs_m + sizeof(signs_m) / sizeof(char));
const string HELP_[] = {"Console calculator help:",
"- Supported operations : '+', '-', '*', '/', '(', ')';",
"- To set variable : '" + VARIABLE_KEY_WORD + " <variable_name> = <value>';",
"- To see declared variables type 'vars';",
"- Use only letters, digits and '_' to name variables;",
"- Variable name can start only with a letter or '_';",
"- Max length of variable name is 20 characters;",
"- Type 'exit' to finish;",
"- Source code : https://github.com/apologist/console_calculator.",
};
const string WELCOME = "Console calculator. Variables are supported. Type expression to calculate. Type 'help' to get help. Type 'vars' to show variables. Type 'exit' to finish.";
#pragma endregion
class calculator
{
public:
calculator(void);
~calculator(void);
void start();
double calculate(const string&, string&);
static void welcome();
static void help();
private:
double calculate_postfix(const string&);
double calculate_postfix_unsafe(const string&);
double calculate_and_show_postfix(const string&);
string convert_to_reverse_polish_notation(const string&);
//validation
private:
string format(const string&);
bool is_valid(const string&, string&);//only for formated strings
//additional functions
private:
bool is_sign(const char&);
bool is_digit(const char&);
bool is_letter(const char&);
string trim(string&);
template <typename T>
vector<T> reverse_v (const vector<T>&);
void split(const string&, char, vector<string>&);
//variables
private:
string divide_spaces(const string&, string&);
map <string, string> variables;
bool process_var_line(string&, string&);
void show_variables();
string var_substitute(const string&, string&);
};
|
Glastis/Random-Hash-Generator
|
gen.h
|
#ifndef GEN_H_
# define GEN_H_
typedef struct
{
size_t max_len;
} t_gen;
/* In ./main.c */
int main(int ac, char **av);
#endif /* ! GEN_H_ */
|
Glastis/Random-Hash-Generator
|
main.c
|
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include "gen.h"
void print_rand_char(int i)
{
srand(time(NULL) + getpid() + i);
printf("%c", (rand() % ('~' - '!')) + '!');
}
int main(int ac, char **av)
{
t_gen all;
size_t i;
i = 0;
all.max_len = 64;
if (ac > 1)
all.max_len = atoi(av[1]);
while (i < all.max_len)
{
print_rand_char(i);
++i;
}
printf("\n");
return (0);
}
|
EnricoCorsaro/Asymptotic
|
include/NonRadialModesPatternModel.h
|
<reponame>EnricoCorsaro/Asymptotic
// Derived class for building the asymptotic relation for radial p modes
// Created by <NAME> @ OACT - August 2019
// e-mail: <EMAIL>
// Header file "NonRadialModesPatternModel.h"
// Implementations contained in "NonRadialModesPatternModel.cpp"
#ifndef NONRADIALMODESPATTERNMODEL_H
#define NONRADIALMODESPATTERNMODEL_H
#include <iostream>
#include "Model.h"
using namespace std;
using Eigen::ArrayXd;
typedef Eigen::Ref<Eigen::ArrayXd> RefArrayXd;
class NonRadialModesPatternModel : public Model
{
public:
NonRadialModesPatternModel(RefArrayXd const covariates, const int angularDegree, const double nuMax, const double DeltaNu,
const double inputEpsilon, const double inputAlpha, const double inputBeta);
~NonRadialModesPatternModel();
virtual void predict(RefArrayXd predictions, RefArrayXd const modelParameters);
protected:
private:
int angularDegree; // The angular degree of the modes to fit
double nuMax; // The frequency of maximum oscillation power
double inputDeltaNu; // The large frequency separation (here used as a fixed parameter)
double inputEpsilon; // The epsilon term of the asymptotic relation (here used as a fixed parameter)
double inputAlpha; // The curvature term for DeltaNu
double inputBeta; // The curvature term for the small frequency separation
};
#endif
|
EnricoCorsaro/Asymptotic
|
include/RadialModesPatternModel.h
|
// Derived class for building the asymptotic relation for radial p modes
// Created by <NAME> @ OACT - August 2019
// e-mail: <EMAIL>
// Header file "RadialModesPatternModel.h"
// Implementations contained in "RadialModesPatternModel.cpp"
#ifndef RADIALMODESPATTERNMODEL_H
#define RADIALMODESPATTERNMODEL_H
#include <iostream>
#include "Model.h"
using namespace std;
using Eigen::ArrayXd;
typedef Eigen::Ref<Eigen::ArrayXd> RefArrayXd;
class RadialModesPatternModel : public Model
{
public:
RadialModesPatternModel(RefArrayXd const covariates, const double nuMax, const double inputEpsilon, const double inputAlpha);
~RadialModesPatternModel();
virtual void predict(RefArrayXd predictions, RefArrayXd const modelParameters);
protected:
private:
double nuMax; // The frequency of maximum oscillation power
double inputEpsilon; // The epsilon term of the asymptotic relation
double inputAlpha; // The curvature term of the asymptotic relation
};
#endif
|
Vichoko/game-of-life-cpu
|
shader_utils.h
|
<reponame>Vichoko/game-of-life-cpu<filename>shader_utils.h
#ifndef _CREATE_SHADER_H
#define _CREATE_SHADER_H
#include <cstdlib>
#include <iostream>
using namespace std;
/* Use glew.h instead of gl.h to get all the GL prototypes declared */
#include <GL/glew.h>
/* Using SDL2 for the base window and OpenGL context init */
#include <SDL.h>
using namespace std;
extern char* file_read(const char* filename);
extern void print_log(GLuint object);
extern GLuint create_shader(const char* filename, GLenum type);
#endif
|
Vichoko/game-of-life-cpu
|
cpu.h
|
<reponame>Vichoko/game-of-life-cpu<gh_stars>1-10
/*
* CPU.h
*
* Created on: 24-09-2017
* Author: vichoko
*/
int isCellAlive(int column, int row);
// graphics
/// display
typedef struct {
float* array;
int total_len;
int vertex_len;
} container_t;
void free_resources();
|
Vichoko/game-of-life-cpu
|
globals.h
|
#define WIDTH 800
#define HEIGHT 800
#define ROWS 128
#define COLUMNS 128
#define FRAMERATE 150
#define INITIAL_LIVES_FRACTION 0.8
#define THREADS_PER_BLOCK 8
|
raulpac/CPPND-System-Monitor
|
include/process.h
|
<filename>include/process.h
#ifndef PROCESS_H
#define PROCESS_H
#include "linux_parser.h"
#include <string>
/*
Basic class for Process representation
It contains relevant attributes as shown below
*/
class Process {
public:
int Pid(); // TODO: See src/process.cpp
std::string User(); // TODO: See src/process.cpp
std::string Command(); // TODO: See src/process.cpp
float CpuUtilization(); // TODO: See src/process.cpp
std::string Ram(); // TODO: See src/process.cpp
long int UpTime(); // TODO: See src/process.cpp
bool operator<(Process const& a) const; // TODO: See src/process.cpp
Process(int Pid){
pid_ = Pid;
user_ = User();
command_ = Command();
cpuutilization_ = CpuUtilization();
ram_ = Ram();
uptime = UpTime();
}
// TODO: Declare any necessary private members
private:
int pid_;
std::string user_;
std::string command_;
float cpuutilization_;
std::string ram_;
long int uptime;
float CpuProc_;
float TUsageTime_; //prev
float TTime_; //prev
};
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/http-s_cfg.h
|
/*
*********************************************************************************************************
* uC/HTTPs
* Hypertext Transfer Protocol (server)
*
* (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/HTTPs is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* HTTP SERVER CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : http-s_cfg.h
* Version : V1.97.00
* Programmer(s) : JDH
* SR
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* HTTPs
*
* Note(s) : (1) #### These configuration defines are not yet being used in the current implementation.
*********************************************************************************************************
*/
#define HTTPs_CFG_IPPORT 80 /* HTTPs IP port. Default is 80. */
#define HTTPs_CFG_IPPORT_SECURE 443 /* HTTPs Secure IP port. Default is 443. */
/* See Note #1. */
#define HTTPs_CFG_MAX_ACCEPT_TIMEOUT_MS 5000 /* Maximum inactivity time (ms) on ACCEPT. */
#define HTTPs_CFG_MAX_RX_TIMEOUT_MS 5000 /* Maximum inactivity time (ms) on RX. */
#define HTTPs_CFG_MAX_TX_TIMEOUT_MS 5000 /* Maximum inactivity time (ms) on TX. */
#define HTTPs_CFG_MAX_ACCEPT_RETRY 1 /* Maximum number of retries on ACCEPT. */
#define HTTPs_CFG_MAX_RX_RETRY 3 /* Maximum number of retries on RX. */
#define HTTPs_CFG_MAX_TX_RETRY 3 /* Maximum number of retries on TX. */
#define HTTPs_CFG_FILE_RD_BUF_LEN 512 /* Length of buffer used to read file. */
#define HTTPs_CFG_FILE_TX_BUF_LEN 512 /* Length of buffer used to send file. */
#define HTTPs_CFG_TOK_PARSE_EN DEF_ENABLED /* Enable / disable token parsing (${}). */
#define HTTPs_CFG_TOK_PARSE_TBL_SIZE 256 /* Size of parse table. Minimum is 2. */
/* Root path for HTTP documents in filesystem. */
#define HTTPs_CFG_FS_ROOT "" /* Filesystem-specific symbols can be used. */
#define HTTPs_CFG_DFLT_FILE "index.html" /* Default file to load if no filename specified in URL.*/
/* Default HTML document returned when the requested */
/* HTML document is not found (HTTP error #404). */
#define HTTPs_CFG_ERR_MSG_HTML_NOT_FOUND "<HTML>\r\n" \
"<BODY>\r\n" \
"<HEAD><TITLE>SYSTEM ERROR</TITLE></HEAD>\r\n" \
"<H1>NOT FOUND</H1>\r\n" \
"The requested object does not exist on this server.\r\n" \
"</BODY>\r\n" \
"</HTML>\r\n"
/*
*********************************************************************************************************
* TRACING
*********************************************************************************************************
*/
#define TRACE_LEVEL_OFF 0
#define TRACE_LEVEL_INFO 1
#define TRACE_LEVEL_DBG 2
#define HTTPs_TRACE_LEVEL TRACE_LEVEL_OFF
#define HTTPs_TRACE (void)
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex5/app_tcpip.c
|
/*
*********************************************************************************************************
* uC/TCP-IP V2
* The Embedded TCP/IP Suite
* Application-Defined Functions
*
* (c) Copyright 2010; Micrium; Weston, FL
* All Rights Reserved
*
* File : APP_TCPIP.C
* By : <NAME>
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
static void AppGraphLCD_IPAddr (NET_IF_NBR if_nbr);
static void AppTCPIP_CfgStaticAddr (NET_IF_NBR if_nbr,
NET_ERR *perr);
#if (APP_CFG_DHCPc_MODULE_EN > 0u)
static void AppDHCPc_Init (DHCPc_ERR *perr);
#endif
static CPU_BOOLEAN AppNetIF_LinkStateWaitUntilUp(NET_IF_NBR if_nbr,
CPU_INT16U retry_max,
CPU_INT32U time_dly_ms,
NET_ERR *perr);
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* AppTCPIP_Init()
*
* Description : This function is called by AppTaskStart() and is responsible for initializing uC/TCP-IP,
* and uC/DHCPc, if enabled.
*
*********************************************************************************************************
*/
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppTCPIP_Init (NET_ERR *perr)
{
NET_IF_NBR if_nbr;
#if (APP_CFG_DHCPc_MODULE_EN > 0u)
DHCPc_ERR dhcp_err;
#endif
CPU_INT32U timeout;
CPU_INT32U retry_dly_ms;
CPU_INT16U retry_max;
CPU_INT16U retry_sec;
CPU_BOOLEAN link_state;
CPU_CHAR err_msg[] = " ret err = xxxxx ";
CPU_CHAR retry_msg[] = "Retrying for xx sec";
/* ------------- INIT NET PROTOCOL STACK -------------- */
*perr = Net_Init();
if (*perr != NET_ERR_NONE) {
Str_FmtNbr_Int32U(*perr,
5u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&err_msg[12]);
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(4, "Net Init failed!");
BSP_GraphLCD_String(5, err_msg);
return;
}
/* ------------------- ADD IF NBR 1 ------------------- */
if_nbr = NetIF_Add((void *)&NetIF_API_Ether, /* Ethernet API */
(void *)&NetDev_API_RX_EtherC, /* Device API structure */
(void *)&NetDev_BSP_RSK2_RX62N, /* Device BSP structure */
(void *)&NetDev_Cfg_RX_Ether_0, /* Device Configuration structure */
(void *)&NetPhy_API_DP83640, /* PHY API structure */
(void *)&NetPhy_Cfg_Generic_0, /* PHY Configuration structure */
(NET_ERR *) perr); /* Return error variable */
if (*perr != NET_IF_ERR_NONE) {
Str_FmtNbr_Int32U(*perr,
5u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&err_msg[12]);
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(4, "NetIF Add failed!");
BSP_GraphLCD_String(5, err_msg);
return;
}
#if (APP_CFG_DHCPc_MODULE_EN == 0u) /* ------------------- CFG IF NBR 1 ------------------- */
AppTCPIP_CfgStaticAddr(if_nbr, perr);
if (*perr != NET_IP_ERR_NONE) {
Str_FmtNbr_Int32U(*perr,
5u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&err_msg[12]);
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(4, "Static Addr failed!");
BSP_GraphLCD_String(5, err_msg);
return;
}
#endif
/* ------------------ START IF NBR 1 ------------------ */
NetIF_Start(if_nbr, perr);
if (*perr != NET_IF_ERR_NONE) {
Str_FmtNbr_Int32U(*perr,
5u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&err_msg[12]);
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(4, "NetIF Start failed!");
BSP_GraphLCD_String(5, err_msg);
return;
}
/* ----------------- WAIT FOR LINK UP ----------------- */
link_state = NetIF_LinkStateGet(if_nbr, /* Chk link state. */
perr);
if (link_state == NET_IF_LINK_DOWN) {
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Ethernet Link Down!");
timeout = 30u;
retry_dly_ms = 50u;
retry_sec = 1u;
retry_max = (retry_sec * DEF_TIME_NBR_mS_PER_SEC) / retry_dly_ms;
while ((timeout > 0u) &&
(link_state == NET_IF_LINK_DOWN)) {
Str_FmtNbr_Int32U(timeout,
2u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_SPACE,
DEF_NO,
DEF_NO,
&retry_msg[13]);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(5, retry_msg);
timeout--;
link_state = AppNetIF_LinkStateWaitUntilUp(if_nbr,
retry_max,
retry_dly_ms,
perr);
}
if (link_state == NET_IF_LINK_UP) {
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Ethernet Link Up!");
}
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(5, "");
}
if (*perr == NET_IF_ERR_NONE) { /* Translate successful return error to NET_ERR_NONE. */
*perr = NET_ERR_NONE;
}
#if (APP_CFG_DHCPc_MODULE_EN == 0u) /* ---------------- MANUALLY CFG'D ADDR --------------- */
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Manually Configured");
AppGraphLCD_IPAddr(if_nbr);
#else
AppDHCPc_Init(&dhcp_err); /* Initialize uC/DHCPc. */
if (dhcp_err != DHCPc_ERR_NONE) { /* If the DHCP client fails to init. */
*perr = NET_ERR_INIT_INCOMPLETE;
Str_FmtNbr_Int32U(dhcp_err,
5u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&err_msg[12]);
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_String(4, "DHCPc Init failed!");
BSP_GraphLCD_String(5, err_msg);
return;
}
#endif
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* AppTCPIP_CfgStaticAddr()
*********************************************************************************************************
*/
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
static void AppTCPIP_CfgStaticAddr (NET_IF_NBR if_nbr,
NET_ERR *perr)
{
NET_IP_ADDR ip;
NET_IP_ADDR msk;
NET_IP_ADDR gateway;
CPU_BOOLEAN cfg_success;
ip = NetASCII_Str_to_IP((CPU_CHAR *)"10.10.1.65", perr);
msk = NetASCII_Str_to_IP((CPU_CHAR *)"255.255.255.0", perr);
gateway = NetASCII_Str_to_IP((CPU_CHAR *)"10.10.1.1", perr);
cfg_success = NetIP_CfgAddrAdd(if_nbr,
ip,
msk,
gateway,
perr);
(void)&cfg_success;
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* AppDHCPc_Init()
*********************************************************************************************************
*/
#if ((APP_CFG_TCPIP_MODULE_EN > 0u) && \
(APP_CFG_DHCPc_MODULE_EN > 0u))
static void AppDHCPc_Init (DHCPc_ERR *perr)
{
CPU_INT08U nbr_if_started;
NET_IF_NBR if_nbr_cur;
DHCPc_OPT_CODE req_param[DHCPc_CFG_PARAM_REQ_TBL_SIZE];
CPU_INT08U req_param_qty;
CPU_INT08U nbr_if_init;
CPU_BOOLEAN if_dhcp_init_tbl[APP_CFG_DHCP_NBR_IF_CFGD];
CPU_INT08U if_done_ix;
DHCPc_STATUS status;
OS_ERR os_err;
NET_ERR err_addr_cfg;
CPU_INT32U cnt;
CPU_BOOLEAN show;
CPU_INT08U col;
*perr = DHCPc_Init();
if (*perr != DHCPc_ERR_NONE) {
return; /* DHCP client initialization failed */
}
req_param[0] = (DHCPc_OPT_CODE)DHCP_OPT_DOMAIN_NAME_SERVER;
req_param_qty = 1;
nbr_if_started = 0;
if_nbr_cur = NET_IF_NBR_BASE_CFGD;
while (nbr_if_started < APP_CFG_DHCP_NBR_IF_CFGD) {
DHCPc_Start((NET_IF_NBR ) if_nbr_cur, /* Starting DHCP */
(DHCPc_OPT_CODE *)&req_param[0],
(CPU_INT08U ) req_param_qty,
(DHCPc_ERR *) perr);
if (*perr != DHCPc_ERR_NONE) {
return; /* FAILED */
}
nbr_if_started++;
if_nbr_cur++;
}
nbr_if_init = 0;
for (if_done_ix = 0; if_done_ix < APP_CFG_DHCP_NBR_IF_CFGD; if_done_ix++) {
if_dhcp_init_tbl[if_done_ix] = DEF_NO;
}
cnt = 0;
while (nbr_if_init < APP_CFG_DHCP_NBR_IF_CFGD) {
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
if_done_ix = 0;
if_nbr_cur = NET_IF_NBR_BASE_CFGD;
show = DEF_TRUE;
while (if_done_ix < APP_CFG_DHCP_NBR_IF_CFGD) {
if (if_dhcp_init_tbl[if_done_ix] != DEF_YES) {
status = DHCPc_ChkStatus(NET_IF_NBR_BASE_CFGD,
perr);
switch (status) {
case DHCP_STATUS_CFG_IN_PROGRESS:
col = cnt / 2;
col %= 12;
if (col > 6) {
col = 12 - col;
}
cnt++;
if (show == DEF_TRUE) {
show = DEF_FALSE;
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_StringPos(4, 1, "Acquiring Network");
BSP_GraphLCD_StringPos(5, 6, "Address");
}
BSP_GraphLCD_ClrLine(6);
BSP_GraphLCD_StringPos(6, 6 + col, ".");
break;
case DHCP_STATUS_CFGD: /* IF configured */
if_dhcp_init_tbl[if_done_ix] = DEF_YES;
nbr_if_init++;
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Assigned by DHCP");
AppGraphLCD_IPAddr(if_nbr_cur);
break;
case DHCP_STATUS_CFGD_NO_TMR: /* IF configured (no timer set) */
if_dhcp_init_tbl[if_done_ix] = DEF_YES;
nbr_if_init++;
AppTCPIP_CfgStaticAddr(nbr_if_init,
&err_addr_cfg);
(void)&err_addr_cfg;
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Assigned by DHCP*");
AppGraphLCD_IPAddr(if_nbr_cur);
break;
case DHCP_STATUS_CFGD_LOCAL_LINK: /* IF configured (link-local addr) */
if_dhcp_init_tbl[if_done_ix] = DEF_YES;
nbr_if_init++;
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Link-Local Address");
AppGraphLCD_IPAddr(if_nbr_cur);
break;
case DHCP_STATUS_FAIL: /* IF configuration failed */
if_dhcp_init_tbl[if_done_ix] = DEF_YES;
nbr_if_init++;
AppTCPIP_CfgStaticAddr(nbr_if_init,
&err_addr_cfg);
(void)&err_addr_cfg;
BSP_GraphLCD_ClrLine(4);
BSP_GraphLCD_String(4, "Manually Configured");
AppGraphLCD_IPAddr(if_nbr_cur);
break;
default:
break;
}
}
if_done_ix++;
if_nbr_cur++;
}
}
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* AppNetIF_LinkStateWaitUntilUp()
*
* Description : Wait for a network interface's link state to be 'UP'.
*
* Argument(s) : if_nbr Network interface number to check link state.
*
* retry_max Maximum number of consecutive socket open retries (see Note #2).
*
* time_dly_ms Transitory socket open delay value, in milliseconds (see Note #2).
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_IF_ERR_NONE Network interface's link state 'UP'.
* NET_IF_ERR_LINK_DOWN Network interface's link state 'DOWN'.
*
* - RETURNED BY NetIF_LinkStateGet() : -
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
* NET_IF_ERR_INVALID_IF Invalid network interface number.
* NET_OS_ERR_LOCK Network access NOT acquired.
*
* Return(s) : NET_IF_LINK_UP, if NO error(s) & network interface's link state is 'UP'.
*
* NET_IF_LINK_DOWN, otherwise.
*
* Caller(s) : Application.
*
* This function is a network protocol suite application interface (API) function & MAY be
* called by application function(s) [see also Note #1].
*
* Note(s) : (1) AppNetIF_LinkStateWaitUntilUp() is called by application function(s) & ... :
*
* (a) MUST NOT be called with the global network lock already acquired; ...
* (b) MUST block ALL other network protocol tasks by pending on & acquiring the global
* network lock (see 'NetIF_LinkStateGet() Note #1b').
*
* This is required since an application's network protocol suite API function access is
* asynchronous to other network protocol tasks.
*
* (2) If a non-zero number of retries is requested then a non-zero time delay SHOULD also be
* requested; otherwise, all retries will most likely fail immediately since no time will
* elapse to wait for & allow the network interface's link state to successfully be 'UP'.
*********************************************************************************************************
*/
/*$PAGE*/
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
CPU_BOOLEAN AppNetIF_LinkStateWaitUntilUp (NET_IF_NBR if_nbr,
CPU_INT16U retry_max,
CPU_INT32U time_dly_ms,
NET_ERR *perr)
{
CPU_BOOLEAN link_state;
CPU_BOOLEAN done;
CPU_BOOLEAN dly;
CPU_INT16U retry_cnt;
NET_ERR err;
NET_ERR err_rtn;
link_state = NET_IF_LINK_DOWN; /* --------- WAIT FOR NET IF LINK STATE 'UP' ---------- */
done = DEF_NO;
dly = DEF_NO;
retry_cnt = 0u;
while ((retry_cnt <= retry_max) && /* While retry <= max retry ... */
(done == DEF_NO)) { /* ... & link NOT UP, ... */
if (dly == DEF_YES) {
NetOS_TimeDly_ms(time_dly_ms,
&err);
}
link_state = NetIF_LinkStateGet(if_nbr, /* ... chk link state. */
&err);
switch (err) {
case NET_IF_ERR_NONE:
if (link_state == NET_IF_LINK_UP) {
done = DEF_YES;
err_rtn = NET_IF_ERR_NONE;
} else {
retry_cnt++;
dly = DEF_YES;
err_rtn = NET_IF_ERR_LINK_DOWN;
}
break;
case NET_ERR_INIT_INCOMPLETE: /* If transitory err(s), ... */
case NET_OS_ERR_LOCK:
retry_cnt++;
dly = DEF_YES; /* ... dly retry. */
err_rtn = err;
break;
case NET_IF_ERR_INVALID_IF:
default:
done = DEF_YES;
err_rtn = err;
break;
}
}
*perr = err_rtn;
return (link_state);
}
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* AppGraphLCD_IPAddr()
*********************************************************************************************************
*/
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
static void AppGraphLCD_IPAddr (NET_IF_NBR if_nbr)
{
NET_IP_ADDR ip_addr_tbl[NET_IP_CFG_IF_MAX_NBR_ADDR];
NET_IP_ADDRS_QTY ip_addr_tbl_qty;
NET_ERR net_err;
NET_IP_ADDR subnet_addr;
NET_IP_ADDR gateway_addr;
CPU_CHAR str_addr[20];
ip_addr_tbl_qty = NET_IP_CFG_IF_MAX_NBR_ADDR;
(void)NetIP_GetAddrHost( if_nbr,
&ip_addr_tbl[0],
&ip_addr_tbl_qty,
&net_err);
if (net_err == NET_IP_ERR_NONE) {
subnet_addr = NetIP_GetAddrSubnetMask (ip_addr_tbl[0],
&net_err);
gateway_addr = NetIP_GetAddrDfltGateway(ip_addr_tbl[0],
&net_err);
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_ClrLine(6);
BSP_GraphLCD_ClrLine(7);
str_addr[0] = ASCII_CHAR_NULL;
Str_Copy(str_addr, "IP: ");
NetASCII_IP_to_Str( ip_addr_tbl[0],
&str_addr[4],
DEF_NO,
&net_err);
BSP_GraphLCD_String(5, str_addr);
str_addr[0] = ASCII_CHAR_NULL;
Str_Copy(str_addr, "Sub:");
NetASCII_IP_to_Str( subnet_addr,
&str_addr[4],
DEF_NO,
&net_err);
BSP_GraphLCD_String(6, str_addr);
str_addr[0] = ASCII_CHAR_NULL;
Str_Copy(str_addr, "GW: ");
NetASCII_IP_to_Str( gateway_addr,
&str_addr[4],
DEF_NO,
&net_err);
BSP_GraphLCD_String(7, str_addr);
}
}
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex5/app_http.c
|
<gh_stars>1-10
/*
*********************************************************************************************************
* EXAMPLE CODE
*
* (c) Copyright 2009-2010; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* Please feel free to use any application code labeled as 'EXAMPLE CODE' in
* your application products. Example code may be used as is, in whole or in
* part, or may be used as a reference only.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* HTTP SERVER EXAMPLE FILE
*
* TEMPLATE
*
* Filename : app.c
* Version : V1.00
* Programmer(s) : JJL
* AA
* SR
*********************************************************************************************************
* Note(s) : (1) Assumes the following versions (or more recent) of software modules are included in
* the project build :
*
* (a) uC/TCP-IP V2.10
* (b) uC/OS-III V3.01.3
* (c) uC/LIB V1.31
* (d) uC/CPU V1.25
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#include <webpages.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define HTTPs_VAL_REQ_BUF_LEN 20u
#define HTML_LED_INPUT_NAME "LED"
#define HTML_LED1_TOGGLE_INPUT_VALUE "LED1"
#define HTML_LED2_TOGGLE_INPUT_VALUE "LED2"
#define LED1 15u
#define LED2 4u
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
CPU_INT16S AppTempSensorDegC;
static CPU_INT16S AppTempSensorDegF;
/*
*********************************************************************************************************
* LOCAL MACRO'S
*********************************************************************************************************
*/
#define APP_TASK_STOP(); { while (DEF_ON) { \
; \
} \
}
#define APP_TEST_FAULT(err_var, err_code) { if ((err_var) != (err_code)) { \
APP_TASK_STOP(); \
} \
}
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void App_TempSensorUpdate(void);
/*$PAGE*/
/*
*********************************************************************************************************
* AppHTTPs_Init
*
* Description : Initialize HTTP server.
*
* Arguments : none.
*
* Returns : none.
*
* Notes : none.
*********************************************************************************************************
*/
void AppHTTPs_Init (void)
{
CPU_BOOLEAN cfg_success;
cfg_success = HTTPs_Init(DEF_NO);
APP_TEST_FAULT(cfg_success, DEF_OK);
cfg_success = Apps_FS_Init();
APP_TEST_FAULT(cfg_success, DEF_OK);
cfg_success = Apps_FS_AddFile((CPU_CHAR *)&STATIC_INDEX_HTML_NAME,
(CPU_CHAR *)&Index_html,
(CPU_INT32U) STATIC_INDEX_HTML_LEN);
APP_TEST_FAULT(cfg_success, DEF_OK);
cfg_success = Apps_FS_AddFile((CPU_CHAR *)&STATIC_LOGO_GIF_NAME,
(CPU_CHAR *)&Logo_Gif,
(CPU_INT32U) STATIC_LOGO_GIF_LEN);
APP_TEST_FAULT(cfg_success, DEF_OK);
BSP_Temp_Init();
App_TempSensorUpdate();
}
/*$PAGE*/
/*
*********************************************************************************************************
* App_TempSensorUpdate()
*
* Description : Monitor temperature sensor.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : AppTaskStart().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void App_TempSensorUpdate (void)
{
static CPU_INT16S temp_sensor = 0;
AppTempSensorDegC = (CPU_INT16S)BSP_Temp_Rd();
AppTempSensorDegF = (AppTempSensorDegC * 9u / 5u) + 32u;
temp_sensor++;
}
/*$PAGE*/
/*
*********************************************************************************************************
* HTTPs_ValReq()
*
* Description : Callback function handling dynamic variable substitution from HTML file.
*
* Argument(s) : p_tok Pointer to string containing the name of the HTML embedded token.
*
* p_val Pointer to string that will receive the value of the HTML embedded token.
*
* Return(s) : DEF_OK, if value of token returned successfully.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : HTTPs_HTML_FileTokParse().
*
* Note(s) : (1) This is a callback function that MUST be implemented in your application.
*
* (2) 'p_val' returned by HTTPs_ValReq() MUST reference a global array in order to prevent
* the caller from accessing an out-of-scope array defined within HTTPs_ValReq().
*********************************************************************************************************
*/
CPU_BOOLEAN HTTPs_ValReq (CPU_CHAR *p_tok,
CPU_CHAR **p_val)
{
static CPU_CHAR val_buf[HTTPs_VAL_REQ_BUF_LEN];
#if (LIB_VERSION >= 126u)
CPU_INT32U ver;
#elif (LIB_STR_CFG_FP_EN == DEF_ENABLED)
CPU_FP32 ver;
#endif
OS_TICK os_time_tick;
#if (LIB_STR_CFG_FP_EN == DEF_ENABLED)
CPU_FP32 os_time_sec;
#else
CPU_INT32U os_time_sec;
CPU_INT32U os_time_ms;
CPU_SIZE_T os_time_len;
#endif
OS_ERR os_err;
(void)Str_Copy(&val_buf[0], "%%%%%%%%");
*p_val = &val_buf[0];
/* --------------------- OS VALUES -------------------- */
if (Str_Cmp(p_tok, "OS_VERSION") == 0) {
#if (LIB_VERSION >= 126u)
#if (OS_VERSION >= 30200u)
ver = OS_VERSION / 10000;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, ' ', DEF_NO, DEF_NO, &val_buf[0]);
val_buf[2] = '.';
ver = (OS_VERSION / 100) % 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_NO, &val_buf[3]);
val_buf[5] = '.';
ver = (OS_VERSION / 1) % 10;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_YES, &val_buf[6]);
val_buf[8] = '\0';
#elif (OS_VERSION > 300u)
ver = OS_VERSION / 1000;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, ' ', DEF_NO, DEF_NO, &val_buf[0]);
val_buf[2] = '.';
ver = (OS_VERSION / 10) % 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_NO, &val_buf[3]);
val_buf[5] = '.';
ver = (OS_VERSION / 1) % 10;
(void)Str_FmtNbr_Int32U(ver, 1, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_YES, &val_buf[6]);
val_buf[8] = '\0';
#else
ver = OS_VERSION / 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, ' ', DEF_NO, DEF_NO, &val_buf[0]);
val_buf[2] = '.';
ver = (OS_VERSION / 1) % 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_YES, &val_buf[3]);
val_buf[5] = '\0';
#endif
#elif (LIB_STR_CFG_FP_EN == DEF_ENABLED)
#if (OS_VERSION > 30200u)
ver = (CPU_FP32)OS_VERSION / 10000;
(void)Str_FmtNbr_32(ver, 2, 2, ' ', DEF_NO, &val_buf[0]);
ver = (CPU_FP32)OS_VERSION / 100;
(void)Str_FmtNbr_32(ver, 0, 2, '\0', DEF_YES, &val_buf[6]);
#elif (OS_VERSION > 300u)
ver = (CPU_FP32)OS_VERSION / 1000;
(void)Str_FmtNbr_32(ver, 2, 2, ' ', DEF_NO, &val_buf[0]);
ver = (CPU_FP32)OS_VERSION / 10;
(void)Str_FmtNbr_32(ver, 0, 1, '\0', DEF_YES, &val_buf[6]);
#else
ver = (CPU_FP32)OS_VERSION / 100;
(void)Str_FmtNbr_32(ver, 2, 2, '\0', DEF_YES, &val_buf[0]);
#endif
#endif
} else if (Str_Cmp(p_tok, "OS_TIME" ) == 0) {
os_time_tick = (OS_TICK )OSTimeGet(&os_err);
#if (LIB_STR_CFG_FP_EN == DEF_ENABLED)
os_time_sec = (CPU_FP32)os_time_tick / OS_CFG_TICK_RATE_HZ;
(void)Str_FmtNbr_32(os_time_sec, 7u, 3u, '\0', DEF_YES, &val_buf[0]);
#else
os_time_sec = (CPU_INT32U)os_time_tick / OS_CFG_TICK_RATE_HZ;
(void)Str_FmtNbr_Int32U(os_time_sec, 7u, DEF_NBR_BASE_DEC, '\0', DEF_NO, DEF_YES, &val_buf[0]);
(void)Str_Cat(&val_buf[0], ".");
os_time_len = Str_Len(&val_buf[0]);
os_time_ms = (CPU_INT32U)os_time_tick % OS_CFG_TICK_RATE_HZ;
os_time_ms *= 1000 / OS_CFG_TICK_RATE_HZ;
(void)Str_FmtNbr_Int32U(os_time_ms, 3u, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_YES, &val_buf[os_time_len]);
#endif
/*$PAGE*/
/* ----------- NETWORK PROTOCOL SUITE VALUES ---------- */
} else if (Str_Cmp(p_tok, "NET_VERSION") == 0) {
#if (LIB_VERSION >= 126u)
#if (NET_VERSION > 205u)
ver = NET_VERSION / 10000;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, ' ', DEF_NO, DEF_NO, &val_buf[0]);
val_buf[2] = '.';
ver = (NET_VERSION / 100) % 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_NO, &val_buf[3]);
val_buf[5] = '.';
ver = (NET_VERSION / 1) % 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_YES, &val_buf[6]);
val_buf[8] = '\0';
#else
ver = NET_VERSION / 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, ' ', DEF_NO, DEF_NO, &val_buf[0]);
val_buf[2] = '.';
ver = (NET_VERSION / 1) % 100;
(void)Str_FmtNbr_Int32U(ver, 2, DEF_NBR_BASE_DEC, '0', DEF_NO, DEF_YES, &val_buf[3]);
val_buf[5] = '\0';
#endif
#elif (LIB_STR_CFG_FP_EN == DEF_ENABLED)
#if (NET_VERSION > 205u)
ver = (CPU_FP32)NET_VERSION / 10000;
(void)Str_FmtNbr_32(ver, 2, 2, ' ', DEF_NO, &val_buf[0]);
ver = (CPU_FP32)NET_VERSION / 100;
(void)Str_FmtNbr_32(ver, 0, 2, '\0', DEF_YES, &val_buf[6]);
#else
ver = (CPU_FP32)NET_VERSION / 100;
(void)Str_FmtNbr_32(ver, 2, 2, '\0', DEF_YES, &val_buf[0]);
#endif
#endif
/* ---------------- APPLICATION VALUES ---------------- */
} else if (Str_Cmp(p_tok, "TEMP_C") == 0) {
(void)Str_FmtNbr_Int32S(AppTempSensorDegC, 3, DEF_NBR_BASE_DEC, '\0', DEF_NO, DEF_YES, &val_buf[0]);
} else if (Str_Cmp(p_tok, "TEMP_F") == 0) {
(void)Str_FmtNbr_Int32S(AppTempSensorDegF, 3, DEF_NBR_BASE_DEC, '\0', DEF_NO, DEF_YES, &val_buf[0]);
}
if ((Str_Cmp(p_tok, "TEMP_C") == 0) || /* Update temperature values. */
(Str_Cmp(p_tok, "TEMP_F") == 0)) {
App_TempSensorUpdate();
}
return DEF_OK;
}
/*$PAGE*/
/*
*********************************************************************************************************
* HTTPs_ValRx()
*
* Description : Callback function handling POST action for every name-value pair received.
*
* Argument(s) : p_var Pointer to string containing the name of the HTTP POST variable.
*
* p_val Pointer to string containing the value of the HTTP POST variable.
*
* Return(s) : DEF_OK, if value of token returned successfully.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : HTTPs_ProcessCGIList().
*
* Note(s) : (1) This is a callback function that MUST be implemented in your application.
*********************************************************************************************************
*/
CPU_BOOLEAN HTTPs_ValRx (CPU_CHAR *p_var,
CPU_CHAR *p_val)
{
CPU_INT16U cmp_str;
CPU_BOOLEAN ret_val;
ret_val = DEF_FAIL;
cmp_str = Str_Cmp((CPU_CHAR *)p_var,
(CPU_CHAR *)HTML_LED_INPUT_NAME);
if (cmp_str == 0) {
cmp_str = Str_Cmp((CPU_CHAR *)p_val, /* Toggle LED 1. */
(CPU_CHAR *)HTML_LED1_TOGGLE_INPUT_VALUE);
if (cmp_str == 0) {
LED_Toggle(LED1);
ret_val = DEF_OK;
}
cmp_str = Str_Cmp((CPU_CHAR *)p_val, /* Toggle LED 2. */
(CPU_CHAR *)HTML_LED2_TOGGLE_INPUT_VALUE);
if (cmp_str == 0) {
LED_Toggle(LED2);
ret_val = DEF_OK;
}
}
return (ret_val);
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib-Ex6/includes.h
|
/*
*********************************************************************************************************
* uC/OS-III
* MASTER INCLUDE FILE
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : INCLUDES.H
* By : FGK
*********************************************************************************************************
*/
#ifndef __INCLUDES_H__
#define __INCLUDES_H__
#include <cpu_core.h>
#include <os.h>
#include <os_app_hooks.h>
#include <bsp.h>
#include <bsp_os.h>
#include <bsp_adt7420.h>
#include <bsp_adxl345.h>
#include <bsp_glcd.h>
#include <math.h>
int snprintf(char *str, CPU_SIZE_T str_m, const char *fmt, /*args*/ ...);
#if (APP_CFG_PROBE_COM_MODULE_EN > 0)
#include <probe_com.h>
#if (PROBE_COM_CFG_RS232_EN > 0)
#include <probe_rs232c.h>
#include <probe_rs232.h>
#endif
#if (PROBE_COM_CFG_TCPIP_EN > 0)
#include <probe_tcpip.h>
#endif
#endif
#if (APP_CFG_TCPIP_MODULE_EN > 0)
#include <net.h>
#include <net_bsp.h>
#include <net_dev_rx_etherc.h>
#include <net_phy_dp83640.h>
#include <net_dev_cfg.h>
#if (APP_CFG_DHCPc_MODULE_EN > 0)
#include <dhcp-c.h>
#endif
#if (APP_CFG_TFTPs_MODULE_EN > 0)
#include <tftp-s.h>
#endif
#endif
#if (APP_CFG_FS_EN > 0)
#include <fs_app.h>
#endif
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/fs_app.h
|
/*
*********************************************************************************************************
* uC/FS V4
* The Embedded File System
*
* (c) Copyright 2008-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/FS is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* FILE SYSTEM APPLICATION INITIALIZATION
*
* TEMPLATE
*
* Filename : fs_app.h
* Version : V4.04
* Programmer(s) : BAN
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*********************************************************************************************************
*/
#ifndef FS_APP_MODULE_PRESENT
#define FS_APP_MODULE_PRESENT
/*
*********************************************************************************************************
* EXTERNS
*********************************************************************************************************
*/
#ifdef FS_APP_MODULE
#define FS_APP_EXT
#else
#define FS_APP_EXT extern
#endif
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <cpu.h>
#include <lib_def.h>
#include <app_cfg.h>
/*
*********************************************************************************************************
* DEFAULT CONFIGURATION
*********************************************************************************************************
*/
#ifndef APP_CFG_FS_EN
#define APP_CFG_FS_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_IDE_EN
#define APP_CFG_FS_IDE_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_MSC_EN
#define APP_CFG_FS_MSC_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_NAND_EN
#define APP_CFG_FS_NAND_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_NOR_EN
#define APP_CFG_FS_NOR_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_RAM_EN
#define APP_CFG_FS_RAM_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_SD_CARD_EN
#define APP_CFG_FS_SD_CARD_EN DEF_DISABLED
#endif
#ifndef APP_CFG_FS_SD_EN
#define APP_CFG_FS_SD_EN DEF_DISABLED
#endif
/*
*********************************************************************************************************
* CONDITIONAL INCLUDE FILES
*********************************************************************************************************
*/
#if (APP_CFG_FS_EN == DEF_ENABLED)
#include <fs.h>
#if (APP_CFG_FS_IDE_EN == DEF_ENABLED)
#include <fs_dev_ide.h>
#endif
#if (APP_CFG_FS_MSC_EN == DEF_ENABLED)
#include <fs_dev_msc.h>
#endif
#if (APP_CFG_FS_NAND_EN == DEF_ENABLED)
#include <fs_dev_nand.h>
#endif
#if (APP_CFG_FS_NOR_EN == DEF_ENABLED)
#include <fs_dev_nor.h>
#endif
#if (APP_CFG_FS_RAM_EN == DEF_ENABLED)
#include <fs_dev_ramdisk.h>
#endif
#if (APP_CFG_FS_SD_CARD_EN == DEF_ENABLED)
#include <fs_dev_sd_card.h>
#endif
#if (APP_CFG_FS_SD_EN == DEF_ENABLED)
#include <fs_dev_sd_spi.h>
#endif
#endif
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#if (APP_CFG_FS_EN == DEF_ENABLED)
CPU_BOOLEAN App_FS_Init(void);
#endif
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
/* ----------------- FS CONFIGURATION ----------------- */
#ifndef APP_CFG_FS_EN
#error "APP_CFG_FS_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_EN != DEF_DISABLED) && \
(APP_CFG_FS_EN != DEF_ENABLED ))
#error "APP_CFG_FS_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif (APP_CFG_FS_EN == DEF_ENABLED)
/* Device count. */
#ifndef APP_CFG_FS_DEV_CNT
#error "APP_CFG_FS_DEV_CNT not #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#elif (APP_CFG_FS_DEV_CNT < 1u)
#error "APP_CFG_FS_DEV_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Volume count. */
#ifndef APP_CFG_FS_VOL_CNT
#error "APP_CFG_FS_VOL_CNT not #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#elif (APP_CFG_FS_VOL_CNT < 1u)
#error "APP_CFG_FS_VOL_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* File count. */
#ifndef APP_CFG_FS_FILE_CNT
#error "APP_CFG_FS_FILE_CNT not #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#elif (APP_CFG_FS_FILE_CNT < 1u)
#error "APP_CFG_FS_FILE_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Directory count. */
#ifndef APP_CFG_FS_DIR_CNT
#error "APP_CFG_FS_DIR_CNT not #define'd in 'app_cfg.h' "
#error " [MUST be >= 0] "
#elif (APP_CFG_FS_DIR_CNT < 0u)
#error "APP_CFG_FS_DIR_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 0] "
#endif
/* Buffer count. */
#ifndef APP_CFG_FS_BUF_CNT
#error "APP_CFG_FS_BUF_CNT not #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#elif (APP_CFG_FS_BUF_CNT < (2u * APP_CFG_FS_VOL_CNT))
#error "APP_CFG_FS_BUF_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Device driver count. */
#ifndef APP_CFG_FS_DEV_DRV_CNT
#error "APP_CFG_FS_DEV_DRV_CNT not #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#elif (APP_CFG_FS_DEV_DRV_CNT < 1u)
#error "APP_CFG_FS_DEV_DRV_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Maximum sector size. */
#ifndef APP_CFG_FS_MAX_SEC_SIZE
#error "APP_CFG_FS_MAX_SEC_SIZE not #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#elif ((APP_CFG_FS_MAX_SEC_SIZE != 512u) && \
(APP_CFG_FS_MAX_SEC_SIZE != 1024u) && \
(APP_CFG_FS_MAX_SEC_SIZE != 2048u) && \
(APP_CFG_FS_MAX_SEC_SIZE != 4096u))
#error "APP_CFG_FS_MAX_SEC_SIZE illegally #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#endif
/* ------------- IDE DRIVER CONFIGURATION ------------- */
#ifndef APP_CFG_FS_IDE_EN
#error "APP_CFG_FS_IDE_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_IDE_EN != DEF_DISABLED) && \
(APP_CFG_FS_IDE_EN != DEF_ENABLED ))
#error "APP_CFG_FS_IDE_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#endif
/* ------------- MSC DRIVER CONFIGURATION ------------- */
#ifndef APP_CFG_FS_MSC_EN
#error "APP_CFG_FS_MSC_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_MSC_EN != DEF_DISABLED) && \
(APP_CFG_FS_MSC_EN != DEF_ENABLED ))
#error "APP_CFG_FS_MSC_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#endif
/* ------------- NAND DRIVER CONFIGURATION ------------ */
#ifndef APP_CFG_FS_NAND_EN
#error "APP_CFG_FS_NAND_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_NAND_EN != DEF_DISABLED) && \
(APP_CFG_FS_NAND_EN != DEF_ENABLED ))
#error "APP_CFG_FS_NAND_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif (APP_CFG_FS_NAND_EN == DEF_ENABLED)
/* First block number. */
#ifndef APP_CFG_FS_NAND_BLK_NBR_FIRST
#error "APP_CFG_FS_NAND_BLK_NBR_FIRST not #define'd in 'app_cfg.h' "
#endif
/* Block count. */
#ifndef APP_CFG_FS_NAND_BLK_CNT
#error "APP_CFG_FS_NAND_BLK_CNT not #define'd in 'app_cfg.h' "
#elif (APP_CFG_FS_NAND_BLK_CNT < 1u)
#error "APP_CFG_FS_NAND_BLK_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Sector size. */
#ifndef APP_CFG_FS_NAND_SEC_SIZE
#error "APP_CFG_FS_NAND_SEC_SIZE not #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#elif ((APP_CFG_FS_NAND_SEC_SIZE != 512u) && \
(APP_CFG_FS_NAND_SEC_SIZE != 1024u) && \
(APP_CFG_FS_NAND_SEC_SIZE != 2048u) && \
(APP_CFG_FS_NAND_SEC_SIZE != 4096u))
#error "APP_CFG_FS_NAND_SEC_SIZE illegally #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#endif
/* Active block count. */
#ifndef APP_CFG_FS_NAND_RB_CNT
#error "APP_CFG_FS_NAND_RB_CNT not #define'd in 'app_cfg.h' "
#elif (APP_CFG_FS_NAND_RB_CNT < 1u)
#error "APP_CFG_FS_NAND_RB_CNT illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* NAND physical-layer driver pointer. */
#ifndef APP_CFG_FS_NAND_PHY_PTR
#error "APP_CFG_FS_NAND_PHY_PTR not #define'd in 'app_cfg.h' "
#endif
/* Bus width. */
#ifndef APP_CFG_FS_NAND_BUS_WIDTH
#error "APP_CFG_FS_NAND_BUS_WIDTH not #define'd in 'app_cfg.h' "
#endif
/* Maximum clock frequency. */
#ifndef APP_CFG_FS_NAND_MAX_CLK_FREQ
#error "APP_CFG_FS_NAND_MAX_CLK_FREQ not #define'd in 'app_cfg.h' "
#endif
#endif
/* ------------- NOR DRIVER CONFIGURATION ------------- */
#ifndef APP_CFG_FS_NOR_EN
#error "APP_CFG_FS_NOR_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_NOR_EN != DEF_DISABLED) && \
(APP_CFG_FS_NOR_EN != DEF_ENABLED ))
#error "APP_CFG_FS_NOR_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif (APP_CFG_FS_NOR_EN == DEF_ENABLED)
/* Base address. */
#ifndef APP_CFG_FS_NOR_ADDR_BASE
#error "APP_CFG_FS_NOR_ADDR_BASE not #define'd in 'app_cfg.h' "
#endif
/* Region number. */
#ifndef APP_CFG_FS_NOR_REGION_NBR
#error "APP_CFG_FS_NOR_REGION_NBR not #define'd in 'app_cfg.h' "
#endif
/* Start address. */
#ifndef APP_CFG_FS_NOR_ADDR_START
#error "APP_CFG_FS_NOR_ADDR_START not #define'd in 'app_cfg.h' "
#elif (APP_CFG_FS_NOR_ADDR_START < APP_CFG_FS_NOR_ADDR_BASE)
#error "APP_CFG_FS_NOR_ADDR_START illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= APP_CFG_FS_NOR_ADDR_BASE] "
#endif
/* Device size. */
#ifndef APP_CFG_FS_NOR_DEV_SIZE
#error "APP_CFG_FS_NOR_DEV_SIZE not #define'd in 'app_cfg.h' "
#elif (APP_CFG_FS_NOR_DEV_SIZE < 1u)
#error "APP_CFG_FS_NOR_DEV_SIZE illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Sector size. */
#ifndef APP_CFG_FS_NOR_SEC_SIZE
#error "APP_CFG_FS_NOR_SEC_SIZE not #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#elif ((APP_CFG_FS_NOR_SEC_SIZE != 512u) && \
(APP_CFG_FS_NOR_SEC_SIZE != 1024u) && \
(APP_CFG_FS_NOR_SEC_SIZE != 2048u) && \
(APP_CFG_FS_NOR_SEC_SIZE != 4096u))
#error "APP_CFG_FS_NOR_SEC_SIZE illegally #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#endif
/* Percentage of device reserved. */
#ifndef APP_CFG_FS_NOR_PCT_RSVD
#error "APP_CFG_FS_NOR_PCT_RSVD not #define'd in 'app_cfg.h' "
#elif ((APP_CFG_FS_NOR_PCT_RSVD < FS_DEV_NOR_PCT_RSVD_MIN) || \
(APP_CFG_FS_NOR_PCT_RSVD > FS_DEV_NOR_PCT_RSVD_MAX))
#error "APP_CFG_FS_NOR_PCT_RSVD illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= FS_DEV_NOR_PCT_RSVD_MIN] "
#error " [ && <= FS_DEV_NOR_PCT_RSVD_MAX] "
#endif
/* Erase count differential threshold. */
#ifndef APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH
#error "APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH not #define'd in 'app_cfg.h' "
#elif ((APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH < FS_DEV_NOR_ERASE_CNT_DIFF_TH_MIN) || \
(APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH > FS_DEV_NOR_ERASE_CNT_DIFF_TH_MAX))
#error "APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= FS_DEV_NOR_ERASE_CNT_DIFF_TH_MIN]"
#error " [ && <= FS_DEV_NOR_ERASE_CNT_DIFF_TH_MAX]"
#endif
/* NOR physical-layer driver pointer. */
#ifndef APP_CFG_FS_NOR_PHY_PTR
#error "APP_CFG_FS_NOR_PHY_PTR not #define'd in 'app_cfg.h' "
#endif
/* Bus width. */
#ifndef APP_CFG_FS_NOR_BUS_WIDTH
#error "APP_CFG_FS_NOR_BUS_WIDTH not #define'd in 'app_cfg.h' "
#endif
/* Maximum bus width. */
#ifndef APP_CFG_FS_NOR_BUS_WIDTH_MAX
#error "APP_CFG_FS_NOR_BUS_WIDTH_MAX not #define'd in 'app_cfg.h' "
#endif
/* Physical device count. */
#ifndef APP_CFG_FS_NOR_PHY_DEV_CNT
#error "APP_CFG_FS_NOR_PHY_DEV_CNT not #define'd in 'app_cfg.h' "
#endif
/* Maximum clock frequency. */
#ifndef APP_CFG_FS_NOR_MAX_CLK_FREQ
#error "APP_CFG_FS_NOR_MAX_CLK_FREQ not #define'd in 'app_cfg.h' "
#endif
#endif
/* ------------- RAM DRIVER CONFIGURATION ------------- */
#ifndef APP_CFG_FS_RAM_EN
#error "APP_CFG_FS_RAM_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_RAM_EN != DEF_DISABLED) && \
(APP_CFG_FS_RAM_EN != DEF_ENABLED ))
#error "APP_CFG_FS_RAM_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif (APP_CFG_FS_RAM_EN == DEF_ENABLED)
/* Number of sectors. */
#ifndef APP_CFG_FS_RAM_NBR_SECS
#error "APP_CFG_FS_RAM_NBR_SECS not #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#elif (APP_CFG_FS_RAM_NBR_SECS < 1u)
#error "APP_CFG_FS_RAM_NBR_SECS illegally #define'd in 'app_cfg.h' "
#error " [MUST be >= 1] "
#endif
/* Sector size. */
#ifndef APP_CFG_FS_RAM_SEC_SIZE
#error "APP_CFG_FS_RAM_SEC_SIZE not #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#elif ((APP_CFG_FS_RAM_SEC_SIZE != 512) && \
(APP_CFG_FS_RAM_SEC_SIZE != 1024) && \
(APP_CFG_FS_RAM_SEC_SIZE != 2048) && \
(APP_CFG_FS_RAM_SEC_SIZE != 4096))
#error "APP_CFG_FS_RAM_SEC_SIZE illegally #define'd in 'app_cfg.h' "
#error " [MUST be 512] "
#error " [ || 1024] "
#error " [ || 2048] "
#error " [ || 4096] "
#endif
#endif
/* ---------- SD (CARD) DRIVER CONFIGURATION ---------- */
#ifndef APP_CFG_FS_SD_CARD_EN
#error "APP_CFG_FS_SD_CARD_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_SD_CARD_EN != DEF_DISABLED) && \
(APP_CFG_FS_SD_CARD_EN != DEF_ENABLED ))
#error "APP_CFG_FS_SD_CARD_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#endif
/* ----------- SD (SPI) DRIVER CONFIGURATION ---------- */
#ifndef APP_CFG_FS_SD_EN
#error "APP_CFG_FS_SD_EN not #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#elif ((APP_CFG_FS_SD_EN != DEF_DISABLED) && \
(APP_CFG_FS_SD_EN != DEF_ENABLED ))
#error "APP_CFG_FS_SD_EN illegally #define'd in 'app_cfg.h' "
#error " [MUST be DEF_DISABLED] "
#error " [ || DEF_ENABLED ] "
#endif
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif /* End of FS app module include. */
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/includes.h
|
/*
*********************************************************************************************************
* uC/OS-III
* MASTER INCLUDE FILE
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : INCLUDES.H
* By : FGK
*********************************************************************************************************
*/
#ifndef __INCLUDES_H__
#define __INCLUDES_H__
#include <cpu_core.h>
#include <os.h>
#include <os_app_hooks.h>
#include <bsp.h>
#include <bsp_os.h>
#include <bsp_adt7420.h>
#include <bsp_adxl345.h>
#include <bsp_glcd.h>
#include <math.h>
#if (APP_CFG_PROBE_COM_MODULE_EN > 0)
#include <probe_com.h>
#if (PROBE_COM_CFG_RS232_EN > 0)
#include <probe_rs232c.h>
#include <probe_rs232.h>
#endif
#if (PROBE_COM_CFG_TCPIP_EN > 0)
#include <probe_tcpip.h>
#endif
#endif
#if (APP_CFG_TCPIP_MODULE_EN > 0)
#include <net.h>
#include <net_bsp.h>
#include <net_dev_rx_etherc.h>
#include <net_phy_dp83640.h>
#include <net_dev_cfg.h>
#include <dhcp-c.h>
#include <http-s.h>
#endif
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/net_dev_cfg.h
|
<filename>uCOS-III-Lib/net_dev_cfg.h<gh_stars>1-10
/*
*********************************************************************************************************
* uC/TCP-IP V2
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK DEVICE CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : net_dev_cfg.h
* Version : V2.11.02
* Programmer(s) : EHS
* FGK
* ITJ
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This network device configuration header file is protected from multiple pre-processor
* inclusion through use of the network module present pre-processor macro definition.
*********************************************************************************************************
*/
#ifndef NET_DEV_CFG_MODULE_PRESENT /* See Note #1. */
#define NET_DEV_CFG_MODULE_PRESENT
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK DEVICE CONFIGURATION
*
* Note(s) : (1) (a) Each network device maps to a unique, developer-configured device configuration that
* MUST be defined in application files, typically 'net_dev_cfg.c', & SHOULD be forward-
* declared with the exact same name & type in order to be used by the application during
* calls to NetIF_Add().
*
* (b) Since these device configuration structures are referenced ONLY by application files,
* there is NO required naming convention for these configuration structures. However,
* the following naming convention is suggested for all developer-configured network
* device configuration structures :
*
* NetDev_Cfg_<Device>[_Number]
*
* where
* <Device> Name of device or device driver
* [Number] Network device number for each specific instance of
* device (optional if the development board does NOT
* support multiple instances of the specific device)
*
* Examples :
*
* NET_DEV_CFG_ETHER NetDev_Cfg_MACB; Ethernet configuration for MACB
*
* NET_DEV_CFG_ETHER NetDev_Cfg_FEC_0; Ethernet configuration for FEC #0
* NET_DEV_CFG_ETHER NetDev_Cfg_FEC_1; Ethernet configuration for FEC #1
*
* NET_DEV_CFG_PPP NetDev_Cfg_UART_2; PPP configuration for UART #2
*********************************************************************************************************
*/
/* Declare each specific devices' configuration (see Note #1) : */
#ifdef NET_IF_MODULE_ETHER_PRESENT
extern const NET_DEV_CFG_ETHER NetDev_Cfg_RX_Ether_0; /* Ethernet configuration for device #0 */
extern const NET_PHY_CFG_ETHER NetPhy_Cfg_Generic_0; /* Ethernet Phy configuration for device #0 */
#endif
/*$PAGE*/
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'net_dev_cfg.h MODULE'.
*********************************************************************************************************
*/
#endif /* End of net dev cfg module include. */
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/audio.h
|
<filename>uCOS-III-Ex6/audio.h<gh_stars>1-10
/*
*********************************************************************************************************
* AUDIO APPLICATION
*
* (c) Copyright 2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* AUDIO MANAGEMENT
* Filename : audio.h
* Version : V1.02
* Programmer(s) : FT
* FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This header file is protected from multiple pre-processor inclusion through use of the
* AUDIO_PRESENT present pre-processor macro definition.
*********************************************************************************************************
*/
#ifndef AUDIO_PRESENT
#define AUDIO_PRESENT
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <cpu.h>
#include <app_cfg.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*
* Note(s): 1) To route the audio output to the SSM2377 daughter card and to enable gain control, the
* AUDIO_CFG_SSM2377_EN must be #define'd to DEF_ENABLED on 'app_cfg.h'.
*********************************************************************************************************
*/
#ifndef AUDIO_CFG_SSM2377_EN
#define AUDIO_CFG_SSM2377_EN DEF_DISABLED
#endif
/*
*********************************************************************************************************
* AUDIO BUFFERING THRESHOLD
*
* Note(s): 1) Audio buffering threshold in milliseconds to delay playback while enqueuing samples.
*********************************************************************************************************
*/
#ifndef AUDIO_CFG_BUF_TH
#define AUDIO_CFG_BUF_TH 10u
#endif
/*
*********************************************************************************************************
* RESOURCE INTERCHANGE FILE FORMAT (RIFF) DEFINES
*********************************************************************************************************
*/
#define RIFF_CHUNK_ID 0x46464952u /* "RIFF" in ASCII. */
#define RIFF_CHUNK_TYPE_PAL 0x204C4150u /* "PAL " in ASCII. */
#define RIFF_CHUNK_TYPE_RDIB 0x42494452u /* "RDIB" in ASCII. */
#define RIFF_CHUNK_TYPE_RMID 0x44494D52u /* "RMID" in ASCII. */
#define RIFF_CHUNK_TYPE_RMMP 0x504D4D52u /* "RMMP" in ASCII. */
#define RIFF_CHUNK_TYPE_WAVE 0x45564157u /* "WAVE" in ASCII. */
#define RIFF_WAVE_CHUNK_ID_FMT 0x20746d66u /* "fmt " in ASCII. */
#define RIFF_WAVE_CHUNK_ID_DATA 0x61746164u /* "data" in ASCII. */
#define RIFF_WAVE_CHUNK_ID_SLNT 0x746e6c73u /* "slnt" in ASCII. */
#define RIFF_WAVE_FMT_TAG_PCM 0x0001 /* Microsoft Pulse Code modulation (PCM) format. */
/*
*********************************************************************************************************
* ENUMS
*********************************************************************************************************
*/
typedef enum audio_stream_fmt {
AUDIO_STREAM_FMT_NONE = 0,
AUDIO_STREAM_FMT_04_ADPCM,
AUDIO_STREAM_FMT_08_UNSIGNED,
AUDIO_STREAM_FMT_16_UNSIGNED,
AUDIO_STREAM_FMT_16_SIGNED
} AUDIO_STREAM_FMT;
/*
*********************************************************************************************************
* FORWARD DECLARATION
*********************************************************************************************************
*/
typedef struct audio_buf AUDIO_BUF;
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
struct audio_buf {
void *DataPtr;
CPU_SIZE_T Samples;
AUDIO_BUF *NextPtr;
};
typedef struct riff_chunk {
CPU_INT32U ID;
CPU_INT32U Size;
} RIFF_CHUNK;
typedef struct riff_fmt {
RIFF_CHUNK Chunk;
CPU_INT32U Fmt;
} RIFF_FMT;
typedef struct pcm_wave_fmt {
CPU_INT16U FmtTag;
CPU_INT16U NbrCh;
CPU_INT32U SamplesPerSec;
CPU_INT32U AvgBytesPerSec;
CPU_INT16U BlkAlign;
CPU_INT16U BitsPerSample;
} PCM_WAVE_FMT;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
CPU_BOOLEAN Audio_Init (void);
CPU_BOOLEAN AudioStream_Open (CPU_INT08U fmt,
CPU_INT08U ch,
CPU_INT32U sample_freq,
CPU_SIZE_T *p_samples_buf);
CPU_BOOLEAN AudioStream_Close (void);
CPU_BOOLEAN AudioStream_VolSet (CPU_INT08U vol);
AUDIO_BUF *AudioBuf_Get (void);
void AudioBuf_Enqueue (AUDIO_BUF *p_buf);
void AudioBuf_Abort (AUDIO_BUF *p_buf);
CPU_SIZE_T AudioUtil_TimeToSamples (CPU_INT32U time);
CPU_SIZE_T AudioUtil_TimeToOctets (CPU_INT32U time);
CPU_SIZE_T AudioUtil_OctetsToSamples(CPU_SIZE_T octets);
CPU_SIZE_T AudioUtil_SamplesToOctets(CPU_SIZE_T samples);
/*
*********************************************************************************************************
* CONFIGURATION ERRORS
*********************************************************************************************************
*/
#ifndef AUDIO_CFG_BUF_NBR
#error "AUDIO_CFG_BUF_NBR not #define'd in 'app_cfg.h'"
#elif (AUDIO_CFG_BUF_NBR < 3u)
#error "AUDIO_CFG_BUF_NBR illegaly #define'd in 'app_cfg.h'"
#error "AUDIO_CFG_BUF_NBR [MUST be >= 3] "
#endif
#ifndef AUDIO_CFG_BUF_SIZE
#error "AUDIO_CFG_BUF_SIZE not #define'd in 'app_cfg.h'"
#elif ((AUDIO_CFG_BUF_SIZE % 4u) != 0u)
#error "AUDIO_CFG_BUF_SIZE illegaly #define'd in 'app_cfg.h'"
#error "AUDIO_CFG_BUF_SIZE [MUST be multiple of 4] "
#endif
/*
*********************************************************************************************************
* MODULE END
*********************************************************************************************************
*/
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/uC-Exosite/exosite.c
|
<reponame>nbarjolin/micrium_gnurx_cloud<gh_stars>1-10
/*
*********************************************************************************************************
* Exosite
* Exosite Device Cloud
*
* (c) Copyright 2011, Exosite
* All Rights Reserved
*
*
* File : EXOSITE.C
* By : CSR
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include "rdk_meta.h"
#include "stdlib.h"
#include <includes.h>
//#include <iodefine.h> // alternate MAC address retrieval
#include <lib_ascii.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define RX_SIZE 50 // must be at least 12 in order to read HTTP status header
#define VEN_SIZE 16
#define OSN_SIZE 30
#define OSV_SIZE 16
#define MAC_LENGTH 12
#define CIK_LENGTH 40
#define PID_LENGTH 9
#define PID "YRDKRX62N"
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static CPU_SIZE_T VEN_LENGTH;
static CPU_CHAR VEN[VEN_SIZE]; // buffer size is fixed, length is arbitrary
static CPU_SIZE_T OSN_LENGTH;
static CPU_CHAR OSN[OSN_SIZE]; // buffer size is fixed, length is arbitrary
static CPU_SIZE_T OSV_LENGTH;
static CPU_CHAR OSV[OSV_SIZE]; // buffer size is fixed, length is arbitrary
static CPU_CHAR MAC[MAC_LENGTH];
static CPU_CHAR CIK[CIK_LENGTH];
static NET_IP_ADDR IP;
static NET_PORT_NBR PORT;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void init_mac_address(NET_IF_NBR if_nbr);
static void init_flash_content(void);
static void activate_device(void);
static void update_m2ip(void);
static void socket_close(NET_SOCK_ID sock);
static NET_SOCK_ID socket_open(void);
static CPU_SIZE_T socket_recv(NET_SOCK_ID sock, CPU_CHAR *rx_buf, CPU_SIZE_T rx_buflen);
static CPU_SIZE_T socket_send(NET_SOCK_ID sock, CPU_CHAR *tx_buf, CPU_SIZE_T tx_buflen);
static CPU_SIZE_T url_encode(CPU_CHAR *buf, CPU_SIZE_T bufsize, CPU_CHAR *str, CPU_SIZE_T strlen);
CPU_BOOLEAN Exosite_Update(void);
/*
*********************************************************************************************************
*********************************************************************************************************
*/
CPU_BOOLEAN Exosite_Reinit(void)
{
CPU_SIZE_T i;
update_m2ip();
activate_device();
for (i = 0; i < CIK_LENGTH; i++)
{
if (!(CIK[i] >= 'a' && CIK[i] <= 'f' || CIK[i] >= '0' && CIK[i] <= '9'))
{
return DEF_FALSE;
}
}
return DEF_TRUE;
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
CPU_BOOLEAN Exosite_Init(CPU_CHAR * pVen, CPU_CHAR * pOS, CPU_CHAR * pVer, NET_IF_NBR if_nbr)
{
init_mac_address(if_nbr);
init_flash_content();
Str_Copy_N(VEN, pVen, VEN_SIZE);
VEN[VEN_SIZE - 1] = 0;
VEN_LENGTH = Str_Len(VEN);
Str_Copy_N(OSN, pOS, OSN_SIZE);
OSN[OSN_SIZE - 1] = 0;
OSN_LENGTH = Str_Len(OSN);
Str_Copy_N(OSV, pVer, OSV_SIZE);
OSV[OSV_SIZE - 1] = 0;
OSV_LENGTH = Str_Len(OSV);
return Exosite_Reinit();
}
/*
*********************************************************************************************************
* Get MAC address
*********************************************************************************************************
*/
CPU_BOOLEAN Exosite_GetMAC(CPU_CHAR * pMAC)
{
CPU_INT16U index = 0;
while(index < MAC_LENGTH)
{
pMAC[index] = MAC[index];
index++;
}
pMAC[index] = ASCII_CHAR_NULL;
return DEF_TRUE;
}
/*
*********************************************************************************************************
* Temporarily set the used CIK to something else
* or reset it to value stored in flash by calling with NULL
*********************************************************************************************************
*/
void Exosite_UseCIK(CPU_CHAR * pCIK)
{
if (NULL != pCIK && 0 != *pCIK)
{
Str_Copy_N(CIK, pCIK, CIK_LENGTH);
}
else
{
rdk_meta *meta_info = (rdk_meta *)RDK_META_LOCATION;
Str_Copy_N(CIK, (CPU_CHAR*)meta_info->cik, CIK_LENGTH);
}
}
/*
*********************************************************************************************************
* Store new CIK in flash
*********************************************************************************************************
*/
void Exosite_SetCIK(CPU_CHAR * pCIK)
{
rdk_meta *meta_info = (rdk_meta *)RDK_META_LOCATION;
if (0 != Str_Cmp_N((CPU_CHAR*)meta_info->cik, pCIK, CIK_LENGTH))
{
rdk_meta_write(pCIK, CIK_LENGTH, meta_info->cik);
}
Str_Copy_N(CIK, pCIK, CIK_LENGTH);
}
/*
*********************************************************************************************************
* NOTE: 'pkey' must be urlencoded
* 'pbuf' is returned urlencoded and must be decoded by the caller.
*********************************************************************************************************
*/
CPU_SIZE_T Exosite_Read(CPU_CHAR *pkey, CPU_CHAR *pbuf, CPU_SIZE_T buflen)
{
NET_SOCK_ID sock;
CPU_SIZE_T len, klen, vlen, rxlen;
CPU_CHAR *p, *pcheck;
CPU_CHAR rx[RX_SIZE];
vlen = 0;
klen = Str_Len(pkey);
pcheck = pkey;
sock = socket_open();
if (-1 == sock)
{
return vlen;
}
if (
24 != socket_send(sock, "GET /api:v1/stack/alias?", 24) ||
klen != socket_send(sock, pkey, klen) ||
12 != socket_send(sock, "= HTTP/1.1\r\n", 12) ||
22 != socket_send(sock, "Host: m2.exosite.com\r\n", 22) ||
15 != socket_send(sock, "X-Exosite-CIK: ", 15) ||
CIK_LENGTH != socket_send(sock, CIK, CIK_LENGTH) ||
2 != socket_send(sock, "\r\n", 2) ||
58 != socket_send(sock, "Accept: application/x-www-form-urlencoded; charset=utf-8\r\n", 58) ||
2 != socket_send(sock, "\r\n", 2)
)
{
socket_close(sock);
return vlen;
}
// @HTTP/x.x NNN@
rxlen = socket_recv(sock, rx, 12);
if (12 == rxlen && '2' == rx[9] && '0' == rx[10] && '0' == rx[11])
{
CPU_CHAR crlf = 0;
do
{
rxlen = socket_recv(sock, rx, RX_SIZE);
len = rxlen;
p = rx;
// Find 4 consecutive \r or \n - should be: \r\n\r\n
while (0 < len && 4 > crlf)
{
if ('\r' == *p || '\n' == *p)
{
++crlf;
}
else
{
crlf = 0;
}
++p;
--len;
}
// The body is "<key>=<value>"
if (0 < len && 4 == crlf && buflen > vlen)
{
// Move past "<key>"
while (0 < len && 0 != *pcheck)
{
if (*pcheck == *p)
{
++pcheck;
}
else
{
pcheck = pkey;
}
++p;
--len;
}
// Match '=', we should now have '<key>='
if (0 < len && 0 == *pcheck && '=' == *p)
{
++p;
--len;
}
// read in the rest of the body as the value
while (0 < len && buflen > vlen)
{
pbuf[vlen++] = *p++;
--len;
}
}
} while (RX_SIZE == rxlen);
}
socket_close(sock);
return vlen;
}
/*
*********************************************************************************************************
* NOTE: 'pkey' and 'pval' must be urlencoded
*********************************************************************************************************
*/
CPU_BOOLEAN Exosite_Write(CPU_CHAR *pkey, CPU_CHAR *pval)
{
CPU_BOOLEAN success = DEF_FALSE;
NET_SOCK_ID sock;
CPU_SIZE_T len, slen, klen, vlen, rxlen;
CPU_CHAR length[4];
CPU_CHAR rx[RX_SIZE];
klen = Str_Len(pkey);
vlen = Str_Len(pval);
len = klen + 1 + vlen; // "<pkey>","=","<pval>"
if (0 == Str_FmtNbr_Int32U (
(CPU_INT32U) len,
(CPU_INT08U) 3,
(CPU_INT08U) 10,
(CPU_CHAR) '\0',
(CPU_BOOLEAN) DEF_YES,
(CPU_BOOLEAN) DEF_YES,
(CPU_CHAR*) length
))
{
return success;
}
slen = Str_Len_N(length, 3);
sock = socket_open();
if (-1 == sock)
{
return success;
}
if (
35 != socket_send(sock, "POST /api:v1/stack/alias HTTP/1.1\r\n", 35) ||
22 != socket_send(sock, "Host: m2.exosite.com\r\n", 22) ||
15 != socket_send(sock, "X-Exosite-CIK: ", 15) ||
CIK_LENGTH != socket_send(sock, CIK, CIK_LENGTH) ||
2 != socket_send(sock, "\r\n", 2) ||
64 != socket_send(sock, "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n", 64) ||
16 != socket_send(sock, "Content-Length: ", 16) ||
slen != socket_send(sock, length, slen) ||
4 != socket_send(sock, "\r\n\r\n", 4) ||
klen != socket_send(sock, pkey, klen) ||
1 != socket_send(sock, "=", 1) ||
vlen != socket_send(sock, pval, vlen)
)
{
socket_close(sock);
return success;
}
// @HTTP/x.x NNN@
rxlen = socket_recv(sock, rx, 12);
if (12 == rxlen && '2' == rx[9] && '0' == rx[10] && '4' == rx[11])
{
success = DEF_TRUE;
}
socket_close(sock);
return success;
}
/*
*********************************************************************************************************
* NOTE: each key and value in 'pkeys' and 'pvalues' must be urlencoded
*********************************************************************************************************
*/
CPU_BOOLEAN Exosite_Write_Batch(CPU_CHAR **pkeys, CPU_CHAR **pvalues, CPU_SIZE_T count)
{
CPU_BOOLEAN success = DEF_FALSE;
NET_SOCK_ID sock;
CPU_SIZE_T len, slen, rxlen;
CPU_CHAR length[4];
CPU_CHAR rx[RX_SIZE];
CPU_SIZE_T i;
if (0 == count)
{
return success;
}
len = 0;
for (i = 0; i < count; i++)
{
len += Str_Len(pkeys[i]) + 1 + Str_Len(pvalues[i]); // "<key>","=","<val>"
}
len += count - 1; // number of '&' chars.
if (0 == Str_FmtNbr_Int32U (
(CPU_INT32U) len,
(CPU_INT08U) 3,
(CPU_INT08U) 10,
(CPU_CHAR) '\0',
(CPU_BOOLEAN) DEF_YES,
(CPU_BOOLEAN) DEF_YES,
(CPU_CHAR*) length
))
{
return success;
}
slen = Str_Len_N(length, 3);
sock = socket_open();
if (-1 == sock)
{
return success;
}
if (
35 != socket_send(sock, "POST /api:v1/stack/alias HTTP/1.1\r\n", 35) ||
22 != socket_send(sock, "Host: m2.exosite.com\r\n", 22) ||
15 != socket_send(sock, "X-Exosite-CIK: ", 15) ||
CIK_LENGTH != socket_send(sock, CIK, CIK_LENGTH) ||
2 != socket_send(sock, "\r\n", 2) ||
64 != socket_send(sock, "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n", 64) ||
16 != socket_send(sock, "Content-Length: ", 16) ||
slen != socket_send(sock, length, slen) ||
4 != socket_send(sock, "\r\n\r\n", 4)
)
{
socket_close(sock);
return success;
}
i = 0;
socket_send(sock, pkeys[i], Str_Len(pkeys[i]));
socket_send(sock, "=", 1);
socket_send(sock, pvalues[i], Str_Len(pvalues[i]));
for (i = 1; i < count; i++)
{
socket_send(sock, "&", 1);
socket_send(sock, pkeys[i], Str_Len(pkeys[i]));
socket_send(sock, "=", 1);
socket_send(sock, pvalues[i], Str_Len(pvalues[i]));
}
// @HTTP/x.x NNN@
rxlen = socket_recv(sock, rx, 12);
if (12 == rxlen && '2' == rx[9] && '0' == rx[10] && '4' == rx[11])
{
success = DEF_TRUE;
}
socket_close(sock);
return success;
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static void activate_device(void)
{
NET_SOCK_ID sock;
CPU_SIZE_T len, slen, rxlen, venlen, osnlen, osvlen;
CPU_CHAR length[4];
CPU_CHAR NCIK[CIK_LENGTH];
CPU_CHAR rx[RX_SIZE];
CPU_CHAR *p, *pVEN, *pOSN, *pOSV;
rdk_meta *meta_info = (rdk_meta *)RDK_META_LOCATION;
pVEN = malloc(VEN_LENGTH * 3 + 1);
venlen = url_encode(pVEN, VEN_LENGTH * 3 + 1, VEN, VEN_LENGTH);
pOSN = malloc(OSN_LENGTH * 3 + 1);
osnlen = url_encode(pOSN, OSN_LENGTH * 3 + 1, OSN, OSN_LENGTH);
pOSV = malloc(OSV_LENGTH * 3 + 1);
osvlen = url_encode(pOSV, OSV_LENGTH * 3 + 1, OSV, OSV_LENGTH);
len = 7 + venlen; // "vendor=",VEN
len += 7 + PID_LENGTH; // "&model=",PID
len += 4 + MAC_LENGTH; // "&sn=",MAC
len += 5 + osnlen; // "&osn=",OSN
len += 5 + osvlen; // "&osv=",OSV
len += 5 + RDK_META_MFR_SIZE; // "&mfr=",MFRDATA
if (0 == Str_FmtNbr_Int32U (
(CPU_INT32U) len,
(CPU_INT08U) 3,
(CPU_INT08U) 10,
(CPU_CHAR) '\0',
(CPU_BOOLEAN) DEF_YES,
(CPU_BOOLEAN) DEF_YES,
(CPU_CHAR*) length
))
{
return;
}
slen = Str_Len_N(length, 3);
sock = socket_open();
if (-1 == sock)
{
return;
}
if (
35 != socket_send(sock, "POST /provision/activate HTTP/1.1\r\n", 35) ||
22 != socket_send(sock, "Host: m2.exosite.com\r\n", 22) ||
64 != socket_send(sock, "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n", 64) ||
35 != socket_send(sock, "Accept: text/plain; charset=utf-8\r\n", 35) ||
16 != socket_send(sock, "Content-Length: ", 16) ||
slen != socket_send(sock, length, slen) ||
4 != socket_send(sock, "\r\n\r\n", 4) ||
7 != socket_send(sock, "vendor=", 7) ||
venlen != socket_send(sock, pVEN, venlen) ||
7 != socket_send(sock, "&model=", 7) ||
PID_LENGTH != socket_send(sock, PID, PID_LENGTH) ||
4 != socket_send(sock, "&sn=", 4) ||
MAC_LENGTH != socket_send(sock, MAC, MAC_LENGTH) ||
5 != socket_send(sock, "&osn=", 5) ||
osnlen != socket_send(sock, pOSN, osnlen) ||
5 != socket_send(sock, "&osv=", 5) ||
osvlen != socket_send(sock, pOSV, osvlen) ||
5 != socket_send(sock, "&mfr=", 5) ||
RDK_META_MFR_SIZE != socket_send(sock, meta_info->mfr, RDK_META_MFR_SIZE)
)
{
socket_close(sock);
return;
}
free(pVEN);
free(pOSN);
free(pOSV);
// @HTTP/x.x NNN@
rxlen = socket_recv(sock, rx, 12);
if (12 == rxlen && '2' == rx[9] && '0' == rx[10] && '0' == rx[11])
{
CPU_CHAR crlf = 0;
CPU_CHAR ciklen = 0;
do
{
rxlen = socket_recv(sock, rx, RX_SIZE);
len = rxlen;
p = rx;
// Find 4 consecutive \r or \n - should be: \r\n\r\n
while (0 < len && 4 > crlf)
{
if ('\r' == *p || '\n' == *p)
{
++crlf;
}
else
{
crlf = 0;
}
++p;
--len;
}
// The body is the CIK
if (0 < len && 4 == crlf && CIK_LENGTH > ciklen)
{
// TODO, be more robust - match Content-Length header value to CIK_LENGTH
CPU_CHAR need, part;
need = CIK_LENGTH - ciklen;
part = need < len ? need : len;
Str_Copy_N(NCIK + ciklen, p, part);
ciklen += part;
}
} while (RX_SIZE == rxlen);
if (CIK_LENGTH == ciklen)
{
Exosite_SetCIK(NCIK);
}
}
socket_close(sock);
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
void update_m2ip(void)
{
NET_SOCK_ID sock;
CPU_SIZE_T len, rxlen, IPLEN = 23; // 23 => 3*6+5 => "nnn,nnn,nnn,nnn,nnn,nnn"
CPU_CHAR *p;
CPU_CHAR rx[RX_SIZE], ip[IPLEN];
sock = socket_open();
if (-1 == sock)
{
return;
}
if (
18 != socket_send(sock, "GET /ip HTTP/1.1\r\n", 18) ||
22 != socket_send(sock, "Host: m2.exosite.com\r\n", 22) ||
35 != socket_send(sock, "Accept: text/plain; charset=utf-8\r\n", 35) ||
2 != socket_send(sock, "\r\n", 2)
)
{
socket_close(sock);
return;
}
// @HTTP/x.x NNN@
rxlen = socket_recv(sock, rx, 12);
if (12 == rxlen && '2' == rx[9] && '0' == rx[10] && '0' == rx[11])
{
CPU_CHAR crlf = 0;
CPU_CHAR iplen = 0;
do
{
rxlen = socket_recv(sock, rx, RX_SIZE);
len = rxlen;
p = rx;
// Find 4 consecutive \r or \n - should be: \r\n\r\n
while (0 < len && 4 > crlf)
{
if ('\r' == *p || '\n' == *p)
{
++crlf;
}
else
{
crlf = 0;
}
++p;
--len;
}
// The body is "nnn,nnn,nnn,nnn,nnn,nnn"
if (0 < len && 4 == crlf && IPLEN > iplen)
{
// TODO, be more robust - match Content-Length header value to IPLEN
CPU_CHAR need, part;
need = IPLEN - iplen;
part = need < len ? need : len;
Str_Copy_N(ip + iplen, p, part);
iplen += part;
}
} while (RX_SIZE == rxlen);
if (0 < iplen && IPLEN >= iplen)
{
CPU_CHAR server_ip[6];
CPU_CHAR i;
p = ip;
for (i = 0; i < 6 || iplen > 0; i++)
{
if (*p >= '0' && *p <= '9')
{
server_ip[i] = *p++ - '0';
if (0 == --iplen) break;
}
if (*p >= '0' && *p <= '9')
{
server_ip[i] *= 10;
server_ip[i] += *p++ - '0';
if (0 == --iplen) break;
}
if (*p >= '0' && *p <= '9')
{
server_ip[i] *= 10;
server_ip[i] += *p++ - '0';
--iplen;
}
if (iplen > 0)
{
if (5 == i || ',' != *p++)
{
break;
}
--iplen;
}
}
if (6 == i)
{
rdk_meta *meta_info = (rdk_meta *)RDK_META_LOCATION;
if (0 != Str_Cmp_N((CPU_CHAR*)meta_info->server, server_ip, 6))
{
rdk_meta_write(server_ip, 6, meta_info->server);
// Convert stored copy to something usable
IP = server_ip[0] * 16777216
+ server_ip[1] * 65536
+ server_ip[2] * 256
+ server_ip[3] * 1;
PORT = server_ip[4] * 256
+ server_ip[5] * 1;
}
}
}
}
socket_close(sock);
return;
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static void init_flash_content(void)
{
rdk_meta *meta_info;
rdk_meta_init();
meta_info = (rdk_meta *)RDK_META_LOCATION;
if (0 != Str_Cmp_N((CPU_CHAR*)meta_info->mark, EXOMARK, Str_Len(EXOMARK)))
{
rdk_meta_defaults();
}
// Get local copy as it can be set temporarily
Str_Copy_N(CIK, (CPU_CHAR*)meta_info->cik, CIK_LENGTH);
// Convert stored copy to something usable
IP = meta_info->server[0] * 16777216
+ meta_info->server[1] * 65536
+ meta_info->server[2] * 256
+ meta_info->server[3] * 1;
PORT = meta_info->server[4] * 256
+ meta_info->server[5] * 1;
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static void init_mac_address(NET_IF_NBR if_nbr)
{
CPU_CHAR hex[] = "0123456789abcdef";
NET_ERR err;
CPU_INT08U addr_hw[6];
CPU_INT08U addr_hw_len = 6;
NetIF_AddrHW_Get(
(NET_IF_NBR ) if_nbr,
(CPU_INT08U *)&addr_hw[0],
(CPU_INT08U *)&addr_hw_len,
(NET_ERR *)&err
);
if (NET_IF_ERR_NONE != err)
{
return;
}
MAC[0] = hex[addr_hw[0] >> 4];
MAC[1] = hex[addr_hw[0] & 15];
MAC[2] = hex[addr_hw[1] >> 4];
MAC[3] = hex[addr_hw[1] & 15];
MAC[4] = hex[addr_hw[2] >> 4];
MAC[5] = hex[addr_hw[2] & 15];
MAC[6] = hex[addr_hw[3] >> 4];
MAC[7] = hex[addr_hw[3] & 15];
MAC[8] = hex[addr_hw[4] >> 4];
MAC[9] = hex[addr_hw[4] & 15];
MAC[10] = hex[addr_hw[5] >> 4];
MAC[11] = hex[addr_hw[5] & 15];
}
/*
static void init_mac_address(void)
{
CPU_CHAR hex[] = "0123456789abcdef";
CPU_INT32U _mahr = ETHERC.MAHR;
CPU_INT16U _malr = ETHERC.MALR.BIT.MA;
MAC[0] = hex[(_mahr >> 28) & 15];
MAC[1] = hex[(_mahr >> 24) & 15];
MAC[2] = hex[(_mahr >> 20) & 15];
MAC[3] = hex[(_mahr >> 16) & 15];
MAC[4] = hex[(_mahr >> 12) & 15];
MAC[5] = hex[(_mahr >> 8) & 15];
MAC[6] = hex[(_mahr >> 4) & 15];
MAC[7] = hex[(_mahr >> 0) & 15];
MAC[8] = hex[(_malr >> 12) & 15];
MAC[9] = hex[(_malr >> 8) & 15];
MAC[10] = hex[(_malr >> 4) & 15];
MAC[11] = hex[(_malr >> 0) & 15];
}
*/
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static void socket_close(NET_SOCK_ID sock)
{
NET_ERR err;
NetSock_CfgTimeoutConnCloseSet(sock, 3000, &err);
NetSock_Close(sock, &err);
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static NET_SOCK_ID socket_open(void)
{
NET_SOCK_ID sock;
NET_SOCK_ADDR_IP sock_addr_ip;
NET_ERR err;
Mem_Clr(
(void *) &sock_addr_ip,
(CPU_SIZE_T) sizeof(sock_addr_ip)
);
sock_addr_ip.AddrFamily = NET_SOCK_ADDR_FAMILY_IP_V4;
sock_addr_ip.Addr = NET_UTIL_HOST_TO_NET_32(IP);
sock_addr_ip.Port = NET_UTIL_HOST_TO_NET_16(PORT);
sock = NetSock_Open(
NET_SOCK_ADDR_FAMILY_IP_V4,
NET_SOCK_TYPE_STREAM,
NET_SOCK_PROTOCOL_TCP,
&err
);
if (NET_SOCK_ERR_NONE != err)
{
return -1;
}
NetSock_CfgTimeoutConnReqSet(sock, 2000, &err);
if (NET_SOCK_ERR_NONE != err)
{
NetSock_Close(sock, &err);
return -1;
}
NetSock_Conn(
(NET_SOCK_ID) sock,
(NET_SOCK_ADDR *) &sock_addr_ip,
(NET_SOCK_ADDR_LEN) sizeof(sock_addr_ip),
(NET_ERR *) &err
);
if (NET_SOCK_ERR_NONE != err)
{
NetSock_Close(sock, &err);
return -1;
}
return sock;
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static CPU_SIZE_T socket_recv(NET_SOCK_ID sock, CPU_CHAR *rx_buf, CPU_SIZE_T rx_buflen)
{
NET_SOCK_RTN_CODE rtn_code;
NET_ERR err;
NetSock_CfgTimeoutRxQ_Set(sock, 5000, &err);
rtn_code = NetSock_RxData(
(NET_SOCK_ID) sock,
(void *) rx_buf,
(CPU_INT16U) rx_buflen,
(CPU_INT16S) NET_SOCK_FLAG_NONE,
&err
);
if (0 >= rtn_code || NET_SOCK_ERR_NONE != err)
{
return 0;
}
return (CPU_SIZE_T)rtn_code;
}
/*
*********************************************************************************************************
*********************************************************************************************************
*/
static CPU_SIZE_T socket_send(NET_SOCK_ID sock, CPU_CHAR *tx_buf, CPU_SIZE_T tx_buflen)
{
NET_SOCK_RTN_CODE rtn_code;
NET_ERR err;
CPU_SIZE_T tx_size = 0;
while (tx_size < tx_buflen)
{
NetSock_CfgTimeoutTxQ_Set(sock, 3000, &err);
rtn_code = NetSock_TxData(
(NET_SOCK_ID) sock,
(void *) (tx_buf + tx_size),
(CPU_INT16U) (tx_buflen - tx_size),
(CPU_INT16S) NET_SOCK_FLAG_NONE,
&err
);
if (0 >= rtn_code || NET_SOCK_ERR_NONE != err)
{
break;
}
tx_size += (CPU_SIZE_T)rtn_code;
}
return tx_size;
}
/*
*********************************************************************************************************
* Snagged from: http://www.geekhideout.com/urlcode.shtml Thanks!
* Modified to use CPU_XXX types and lib_ascii and to accept input/output buffers
*********************************************************************************************************
*/
/* Converts a hex character to its integer value */
static CPU_CHAR from_hex(CPU_CHAR ch)
{
return ASCII_IsDig(ch) ? ch - '0' : ASCII_ToLower(ch) - 'a' + 10;
}
/* Converts an integer value to its hex character*/
static CPU_CHAR to_hex(CPU_CHAR code)
{
static CPU_CHAR hex[] = "0123456789abcdef";
return hex[code & 15];
}
/* Returns a url-encoded version of str */
static CPU_SIZE_T url_encode(CPU_CHAR *buf, CPU_SIZE_T bufsize, CPU_CHAR *str, CPU_SIZE_T strlen)
{
CPU_SIZE_T len = 0;
CPU_CHAR *pstr = str, *pbuf = buf;
// leave room for terminating char. No one would ever pass in zero of course.</sarcasm>
--bufsize;
while (strlen && *pstr && len < bufsize)
{
if (ASCII_IsAlphaNum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~')
{
*pbuf++ = *pstr;
len += 1;
}
else if (*pstr == ' ')
{
*pbuf++ = '+';
len += 1;
}
else if (len + 3 > bufsize)
{
break;
}
else
{
*pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
len += 3;
}
++pstr;
--strlen;
}
*pbuf = '\0';
return len;
}
/* Returns a url-decoded version of str */
static CPU_SIZE_T url_decode(CPU_CHAR *buf, CPU_SIZE_T bufsize, CPU_CHAR *str, CPU_SIZE_T strlen)
{
CPU_SIZE_T len = 0;
CPU_CHAR *pstr = str, *pbuf = buf;
// leave room for terminating char. No one would ever pass in zero of course.</sarcasm>
--bufsize;
while (strlen && *pstr && len < bufsize)
{
if (*pstr == '%')
{
if (!(2 < strlen && pstr[1] && pstr[2]))
{
break;
}
*pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
pstr += 2;
strlen -= 2;
}
else if (*pstr == '+')
{
*pbuf++ = ' ';
}
else
{
*pbuf++ = *pstr;
}
++pstr;
--strlen;
++len;
}
*pbuf = '\0';
return len;
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex4/Init/vects.c
|
/***********************************************************************/
/* */
/* FILE :vects.c */
/* DATE :Mon, Jun 28, 2010 */
/* DESCRIPTION :Vector Table */
/* CPU TYPE :Other */
/* */
/* This file is generated by KPIT GNU Project Generator. */
/* */
/***********************************************************************/
#include "inthandler.h"
#include <includes.h>
typedef void (*fp) (void);
extern void start (void);
extern void stack (void);
extern void OSTickISR (void);
extern void OSCtxSw (void);
extern void AppPWM_ISR_ASM (void);
extern void AppADC_ISR (void);
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
extern void NetDevISR (void);
#endif
#if ((APP_CFG_PROBE_COM_MODULE_EN > 0u) && \
(PROBE_COM_CFG_RS232_EN > 0u))
extern void Probe_ER_ISR (void);
extern void Probe_RX_ISR (void);
extern void Probe_TX_ISR (void);
extern void Probe_TE_ISR (void);
#endif
#define FVECT_SECT __attribute__ ((section (".fvectors")))
const fp HardwareVectors[] FVECT_SECT = {
//;0xffffff80 Reserved
(fp)0,
//;0xffffff84 Reserved
(fp)0,
//;0xffffff88 Reserved
(fp)0,
//;0xffffff8C Reserved
(fp)0,
//;0xffffff90 Reserved
(fp)0,
//;0xffffff94 Reserved
(fp)0,
//;0xffffff98 Reserved
(fp)0,
//;0xffffff9C Reserved
(fp)0,
//;0xffffffA0 Reserved
(fp)0,
//;0xffffffA4 Reserved
(fp)0,
//;0xffffffA8 Reserved
(fp)0,
//;0xffffffAC Reserved
(fp)0,
//;0xffffffB0 Reserved
(fp)0,
//;0xffffffB4 Reserved
(fp)0,
//;0xffffffB8 Reserved
(fp)0,
//;0xffffffBC Reserved
(fp)0,
//;0xffffffC0 Reserved
(fp)0,
//;0xffffffC4 Reserved
(fp)0,
//;0xffffffC8 Reserved
(fp)0,
//;0xffffffCC Reserved
(fp)0,
//;0xffffffd0 Exception(Supervisor Instruction)
INT_Excep_SuperVisorInst,
//;0xffffffd4 Reserved
(fp)0,
//;0xffffffd8 Reserved
(fp)0,
//;0xffffffdc Exception(Undefined Instruction)
INT_Excep_UndefinedInst,
//;0xffffffe0 Reserved
(fp)0,
//;0xffffffe4 Exception(Floating Point)
INT_Excep_FloatingPoint,
//;0xffffffe8 Reserved
(fp)0,
//;0xffffffec Reserved
(fp)0,
//;0xfffffff0 Reserved
(fp)0,
//;0xfffffff4 Reserved
(fp)0,
//;0xfffffff8 NMI
INT_NonMaskableInterrupt,
//;0xfffffffc RESET
//;<<VECTOR DATA START (POWER ON RESET)>>
//;Power On Reset PC
start
//;<<VECTOR DATA END (POWER ON RESET)>>
};
#define RVECT_SECT __attribute__ ((section (".rvectors")))
const fp RelocatableVectors[] RVECT_SECT = {
//;0x0000 Reserved
(fp)0,
//;0x0004 Reserved
(fp)OSCtxSw,
//;0x0008 Reserved
(fp)0,
//;0x000C Reserved
(fp)0,
//;0x0010 Reserved
(fp)0,
//;0x0014 Reserved
(fp)0,
//;0x0018 Reserved
(fp)0,
//;0x001C Reserved
(fp)0,
//;0x0020 Reserved
(fp)0,
//;0x0024 Reserved
(fp)0,
//;0x0028 Reserved
(fp)0,
//;0x002C Reserved
(fp)0,
//;0x0030 Reserved
(fp)0,
//;0x0034 Reserved
(fp)0,
//;0x0038 Reserved
(fp)0,
//;0x003C Reserved
(fp)0,
//;0x0040 BUSERR
(fp)INT_Excep_BUSERR,
//;0x0044 Reserved
(fp)0,
//;0x0048 Reserved
(fp)0,
//;0x004C Reserved
(fp)0,
//;0x0050 Reserved
(fp)0,
//;0x0054 FCUERR
(fp)INT_Excep_FCU_FCUERR,
//;0x0058 Reserved
(fp)0,
//;0x005C FRDYI
(fp)INT_Excep_FCU_FRDYI,
//;0x0060 Reserved
(fp)0,
//;0x0064 Reserved
(fp)0,
//;0x0068 Reserved
(fp)0,
//;0x006C ICU_SWINT
(fp)INT_Excep_ICU_SWINT,
//;0x0070 CMTU0_CMT0
// (fp)INT_Excep_CMTU0_CMT0,
(fp)OSTickISR,
//;0x0074 CMTU0_CMT1
(fp)INT_Excep_CMTU0_CMT1,
//;0x0078 CMTU1_CMT2
(fp)INT_Excep_CMTU1_CMT2,
//;0x007C CMTU1_CMT3
(fp)INT_Excep_CMTU1_CMT3,
//;0x0080 Ether_EINT
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
(fp)NetDevISR,
#else
(fp)INT_Excep_Ether_EINT,
#endif
//;0x0084 Reserved
(fp)0,
//;0x0088 Reserved
(fp)0,
//;0x008C Reserved
(fp)0,
//;0x0090 USB0_D0FIFO0
(fp)INT_Excep_USB0_D0FIFO0,
//;0x0094 USB0_D1FIFO0
(fp)INT_Excep_USB0_D1FIFO0,
//;0x0098 USB0_USBI0
(fp)INT_Excep_USB0_USBI0,
//;0x009C Reserved
(fp)0,
//;0x00A0 USB1_D0FIFO0
(fp)INT_Excep_USB1_D0FIFO1,
//;0x00A4 USB1_D1FIFO0
(fp)INT_Excep_USB1_D1FIFO1,
//;0x00A8 USB1_USBI0
(fp)INT_Excep_USB1_USBI1,
//;0x00AC Reserved
(fp)0,
//;0x00B0 RSPI0_SPEI0
(fp)INT_Excep_RSPI0_SPEI0,
//;0x00B4 RSPI0_SPRI0
(fp)INT_Excep_RSPI0_SPRI0,
//;0x00B8 RSPI0_SPTI0
(fp)INT_Excep_RSPI0_SPTI0,
//;0x00BC RSPI0_SPII0
(fp)INT_Excep_RSPI0_SPII0,
//;0x00C0 RSPI1_SPEI1
(fp)INT_Excep_RSPI1_SPEI1,
//;0x00C4 RSPI1_SPRI1
(fp)INT_Excep_RSPI1_SPRI1,
//;0x00C8 RSPI1_SPTI1
(fp)INT_Excep_RSPI1_SPTI1,
//;0x00CC RSPI1_SPII1
(fp)INT_Excep_RSPI1_SPII1,
//;0x00D0 Reserved
(fp)0,
//;0x00D4 Reserved
(fp)0,
//;0x00D8 Reserved
(fp)0,
//;0x00DC Reserved
(fp)0,
//;0x00E0 CAN0_ERS0
(fp)INT_Excep_CAN0_ERS0,
//;0x00E4 CAN0_RXF0
(fp)INT_Excep_CAN0_RXF0,
//;0x00E8 CAN0_TXF0
(fp)INT_Excep_CAN0_TXF0,
//;0x00EC CAN0_RXM0
(fp)INT_Excep_CAN0_RXM0,
//;0x00F0 CAN0_TXM0
(fp)INT_Excep_CAN0_TXM0,
//;0x00F4 Reserved
(fp)0,
//;0x00F8 RTC_PRD
(fp)INT_Excep_RTC_PRD,
//;0x00FC RTC_CUP
(fp)INT_Excep_RTC_CUP,
//;0x0100 IRQ0
(fp)INT_Excep_IRQ0,
//;0x0104 IRQ1
(fp)INT_Excep_IRQ1,
//;0x0108 IRQ2
(fp)INT_Excep_IRQ2,
//;0x010C IRQ3
(fp)INT_Excep_IRQ3,
//;0x0110 IRQ4
(fp)INT_Excep_IRQ4,
//;0x0114 IRQ5
(fp)INT_Excep_IRQ5,
//;0x0118 IRQ6
(fp)INT_Excep_IRQ6,
//;0x011C IRQ7
(fp)INT_Excep_IRQ7,
//;0x0120 IRQ8
(fp)INT_Excep_IRQ8,
//;0x0124 IRQ9
(fp)INT_Excep_IRQ9,
//;0x0128 IRQ10
(fp)INT_Excep_IRQ10,
//;0x012C IRQ11
(fp)INT_Excep_IRQ11,
//;0x0130 IRQ12
(fp)INT_Excep_IRQ12,
//;0x0134 IRQ13
(fp)INT_Excep_IRQ13,
//;0x0138 IRQ14
(fp)INT_Excep_IRQ14,
//;0x013C IRQ15
(fp)INT_Excep_IRQ15,
//;0x0140 Reserved
(fp)0,
//;0x0144 Reserved
(fp)0,
//;0x0148 Reserved
(fp)0,
//;0x014C Reserved
(fp)0,
//;0x0150 Reserved
(fp)0,
//;0x0154 Reserved
(fp)0,
//;0x0158 Reserved
(fp)0,
//;0x015C Reserved
(fp)0,
//;0x0160 Reserved
(fp)0,
//;0x0164 Reserved
(fp)0,
//;0x0168 USB_resume_USBR0
(fp)INT_Excep_USB_resume_USBR0,
//;0x016C USB_resume_USBR1
(fp)INT_Excep_USB_resume_USBR1,
//;0x0170 RTC_ALM
(fp)INT_Excep_RTC_ALM,
//;0x0174 Reserved
(fp)0,
//;0x0178 Reserved
(fp)0,
//;0x017C Reserved
(fp)0,
//;0x0180 WDT_WOVI
(fp)INT_Excep_WDT_WOVI,
//;0x0184 Reserved
(fp)0,
//;0x0188 AD0_ADI0
(fp)INT_Excep_AD0_ADI0,
//;0x018C AD1_ADI1
(fp)INT_Excep_AD1_ADI1,
//;0x0190 Reserved
(fp)0,
//;0x0194 Reserved
(fp)0,
//;0x0198 S12AD_ADI12_0
(fp)AppADC_ISR,
//;0x019C Reserved
(fp)0,
//;0x01A0 Reserved
(fp)0,
//;0x01A4 Reserved
(fp)0,
//;0x01A8 Reserved
(fp)0,
//;0x01AC Reserved
(fp)0,
//;0x01B0 Reserved
(fp)0,
//;0x01B4 Reserved
(fp)0,
//;0x01B8 Reserved
(fp)0,
//;0x01BC Reserved
(fp)0,
//;0x01C0 Reserved
(fp)0,
//;0x01C4 Reserved
(fp)0,
//;0x01C8 MTU0_TGIA0
(fp)INT_Excep_MTU0_TGIA0,
//;0x01CC MTU0_TGIB0
(fp)INT_Excep_MTU0_TGIB0,
//;0x01D0 MTU0_TGIC0
(fp)INT_Excep_MTU0_TGIC0,
//;0x01D4 MTU0_TGID0
(fp)INT_Excep_MTU0_TGID0,
//;0x01D8 MTU0_TGIV0
(fp)INT_Excep_MTU0_TGIV0,
//;0x01DC MTU0_TGIE0
(fp)INT_Excep_MTU0_TGIE0,
//;0x01E0 MTU0_TGIF0
(fp)INT_Excep_MTU0_TGIF0,
//;0x01E4 MTU1_TGIA1
(fp)INT_Excep_MTU1_TGIA1,
//;0x01E8 MTU1_TGIB1
(fp)INT_Excep_MTU1_TGIB1,
//;0x01EC MTU1_TGIV1
(fp)INT_Excep_MTU1_TGIV1,
//;0x01F0 MTU1_TGIU1
(fp)INT_Excep_MTU1_TGIU1,
//;0x01F4 MTU2_TGIA2
(fp)INT_Excep_MTU2_TGIA2,
//;0x01F8 MTU2_TGIB2
(fp)INT_Excep_MTU2_TGIB2,
//;0x01FC MTU2_TGIV2
(fp)INT_Excep_MTU2_TGIV2,
//;0x0200 MTU2_TGIU2
(fp)INT_Excep_MTU2_TGIU2,
//;0x0204 MTU3_TGIA3
(fp)AppPWM_ISR_ASM,
//;0x0208 MTU3_TGIB3
(fp)INT_Excep_MTU3_TGIB3,
//;0x020C MTU3_TGIC3
(fp)INT_Excep_MTU3_TGIC3,
//;0x0210 MTU3_TGID3
(fp)INT_Excep_MTU3_TGID3,
//;0x0214 MTU3_TGIV3
(fp)INT_Excep_MTU3_TGIV3,
//;0x0218 MTU4_TGIA4
(fp)INT_Excep_MTU4_TGIA4,
//;0x021C MTU4_TGIB4
(fp)INT_Excep_MTU4_TGIB4,
//;0x0220 MTU4_TGIC4
(fp)INT_Excep_MTU4_TGIC4,
//;0x0224 MTU4_TGID4
(fp)INT_Excep_MTU4_TGID4,
//;0x0228 MTU4_TGIV4
(fp)INT_Excep_MTU4_TGIV4,
//;0x022C MTU5_TGIU5
(fp)INT_Excep_MTU5_TGIU5,
//;0x0230 MTU5_TGIV5
(fp)INT_Excep_MTU5_TGIV5,
//;0x0234 MTU5_TGIW5
(fp)INT_Excep_MTU5_TGIW5,
//;0x0238 MTU6_TGIA6
(fp)INT_Excep_MTU6_TGIA6,
//;0x023C MTU6_TGIB6
(fp)INT_Excep_MTU6_TGIB6,
//;0x0240 MTU6_TGIC6
(fp)INT_Excep_MTU6_TGIC6,
//;0x0244 MTU6_TGID6
(fp)INT_Excep_MTU6_TGID6,
//;0x0248 MTU6_TGIV6
(fp)INT_Excep_MTU6_TGIV6,
//;0x024C MTU6_TGIE6
(fp)INT_Excep_MTU6_TGIE6,
//;0x0250 MTU6_TGIF6
(fp)INT_Excep_MTU6_TGIF6,
//;0x0254 MTU7_TGIA7
(fp)INT_Excep_MTU7_TGIA7,
//;0x0258 MTU7_TGIB7
(fp)INT_Excep_MTU7_TGIB7,
//;0x025C MTU7_TGIV7
(fp)INT_Excep_MTU7_TGIV7,
//;0x0260 MTU7_TGIU7
(fp)INT_Excep_MTU7_TGIU7,
//;0x0264 MTU8_TGIA8
(fp)INT_Excep_MTU8_TGIA8,
//;0x0268 MTU8_TGIB8
(fp)INT_Excep_MTU8_TGIB8,
//;0x026C MTU8_TGIV8
(fp)INT_Excep_MTU8_TGIV8,
//;0x0270 MTU8_TGIU8
(fp)INT_Excep_MTU8_TGIU8,
//;0x0274 MTU9_TGIA9
(fp)INT_Excep_MTU9_TGIA9,
//;0x0278 MTU9_TGIB9
(fp)INT_Excep_MTU9_TGIB9,
//;0x027C MTU9_TGIC9
(fp)INT_Excep_MTU9_TGIC9,
//;0x0280 MTU9_TGID9
(fp)INT_Excep_MTU9_TGID9,
//;0x0284 MTU9_TGIV9
(fp)INT_Excep_MTU9_TGIV9,
//;0x0288 MTU10_TGIA10
(fp)INT_Excep_MTU10_TGIA10,
//;0x028C MTU10_TGIB10
(fp)INT_Excep_MTU10_TGIB10,
//;0x0290 MTU10_TGIC10
(fp)INT_Excep_MTU10_TGIC10,
//;0x0294 MTU10_TGID10
(fp)INT_Excep_MTU10_TGID10,
//;0x0298 MTU10_TGIV10
(fp)INT_Excep_MTU10_TGIV10,
//;0x029C MTU11_TGIU11
(fp)INT_Excep_MTU11_TGIU11,
//;0x02A0 MTU11_TGIV11
(fp)INT_Excep_MTU11_TGIV11,
//;0x02A4 MTU11_TGIW11
(fp)INT_Excep_MTU11_TGIW11,
//;0x02A8 POE_OEI1
(fp)INT_Excep_POE_OEI1,
//;0x02AC POE_OEI2
(fp)INT_Excep_POE_OEI2,
//;0x02B0 POE_OEI3
(fp)INT_Excep_POE_OEI3,
//;0x02B4 POE_OEI4
(fp)INT_Excep_POE_OEI4,
//;0x02B8 TMR0_CMI0A
(fp)INT_Excep_TMR0_CMI0A,
//;0x02BC TMR0_CMI0B
(fp)INT_Excep_TMR0_CMI0B,
//;0x02C0 TMR0_OV0I
(fp)INT_Excep_TMR0_OV0I,
//;0x02C4 TMR1_CMI1A
(fp)INT_Excep_TMR1_CMI1A,
//;0x02C8 TMR1_CMI1B
(fp)INT_Excep_TMR1_CMI1B,
//;0x02CC TMR1_OV1I
(fp)INT_Excep_TMR1_OV1I,
//;0x02D0 TMR2_CMI2A
(fp)INT_Excep_TMR2_CMI2A,
//;0x02D4 TMR2_CMI2B
(fp)INT_Excep_TMR2_CMI2B,
//;0x02D8 TMR2_OV2I
(fp)INT_Excep_TMR2_OV2I,
//;0x02DC TMR3_CMI3A
(fp)INT_Excep_TMR3_CMI3A,
//;0x02E0 TMR3_CMI3B
(fp)INT_Excep_TMR3_CMI3B,
//;0x02E4 TMR3_OV3I
(fp)INT_Excep_TMR3_OV3I,
//;0x02E8 Reserved
(fp)0,
//;0x02EC Reserved
(fp)0,
//;0x02F0 Reserved
(fp)0,
//;0x02F4 Reserved
(fp)0,
//;0x02F8 Reserved
(fp)0,
//;0x02FC Reserved
(fp)0,
//;0x0300 Reserved
(fp)0,
//;0x0304 Reserved
(fp)0,
//;0x0308 Reserved
(fp)0,
//;0x030C Reserved
(fp)0,
//;0x0310 Reserved
(fp)0,
//;0x0314 Reserved
(fp)0,
//;0x0318 DMACA_DMAC0I
(fp)INT_Excep_DMACA_DMAC0I,
//;0x031C DMACA_DMAC1I
(fp)INT_Excep_DMACA_DMAC1I,
//;0x0320 DMACA_DMAC2I
(fp)INT_Excep_DMACA_DMAC2I,
//;0x0324 DMACA_DMAC3I
(fp)INT_Excep_DMACA_DMAC3I,
//;0x0328 EXDMAC_EXDMAC0I
(fp)INT_Excep_EXDMAC_EXDMAC0I,
//;0x032C EXDMAC_EXDMAC1I
(fp)INT_Excep_EXDMAC_EXDMAC1I,
//;0x0330 Reserved
(fp)0,
//;0x0334 Reserved
(fp)0,
//;0x0338 Reserved
(fp)0,
//;0x033C Reserved
(fp)0,
//;0x0340 Reserved
(fp)0,
//;0x0344 Reserved
(fp)0,
//;0x0348 Reserved
(fp)0,
//;0x034C Reserved
(fp)0,
//;0x0350 Reserved
(fp)0,
//;0x0354 Reserved
(fp)0,
//;0x0358 SCI0_ERI0
(fp)INT_Excep_SCI0_ERI0,
//;0x035C SCI0_RXI0
(fp)INT_Excep_SCI0_RXI0,
//;0x0360 SCI0_TXI0
(fp)INT_Excep_SCI0_TXI0,
//;0x0364 SCI0_TEI0
(fp)INT_Excep_SCI0_TEI0,
//;0x0368 SCI1_ERI1
(fp)INT_Excep_SCI1_ERI1,
//;0x036C SCI1_RXI1
(fp)INT_Excep_SCI1_RXI1,
//;0x0370 SCI1_TXI1
(fp)INT_Excep_SCI1_TXI1,
//;0x0374 SCI1_TEI1
(fp)INT_Excep_SCI1_TEI1,
//;0x0378 SCI2_ERI2
#if ((APP_CFG_PROBE_COM_MODULE_EN > 0u) && \
(PROBE_COM_CFG_RS232_EN > 0u))
(fp)Probe_ER_ISR,
#else
(fp)INT_Excep_SCI2_ERI2,
#endif
//;0x037C SCI2_RXI2
#if ((APP_CFG_PROBE_COM_MODULE_EN > 0u) && \
(PROBE_COM_CFG_RS232_EN > 0u))
(fp)Probe_RX_ISR,
#else
(fp)INT_Excep_SCI2_RXI2,
#endif
//;0x0380 SCI2_TXI2
#if ((APP_CFG_PROBE_COM_MODULE_EN > 0u) && \
(PROBE_COM_CFG_RS232_EN > 0u))
(fp)Probe_TX_ISR,
#else
(fp)INT_Excep_SCI2_TXI2,
#endif
//;0x0384 SCI2_TEI2
#if ((APP_CFG_PROBE_COM_MODULE_EN > 0u) && \
(PROBE_COM_CFG_RS232_EN > 0u))
(fp)Probe_TE_ISR,
#else
(fp)INT_Excep_SCI2_TEI2,
#endif
//;0x0388 SCI3_ERI3
(fp)INT_Excep_SCI3_ERI3,
//;0x038C SCI3_RXI3
(fp)INT_Excep_SCI3_RXI3,
//;0x0390 SCI3_TXI3
(fp)INT_Excep_SCI3_TXI3,
//;0x0394 SCI3_TEI3
(fp)INT_Excep_SCI3_TEI3,
//;0x0398 Reserved
(fp)0,
//;0x039C Reserved
(fp)0,
//;0x03A0 Reserved
(fp)0,
//;0x03A4 Reserved
(fp)0,
//;0x03A8 SCI5_ERI5
(fp)INT_Excep_SCI5_ERI5,
//;0x03AC SCI5_RXI5
(fp)INT_Excep_SCI5_RXI5,
//;0x03B0 SCI5_TXI5
(fp)INT_Excep_SCI5_TXI5,
//;0x03B4 SCI5_TEI5
(fp)INT_Excep_SCI5_TEI5,
//;0x03B8 SCI6_ERI6
(fp)INT_Excep_SCI6_ERI6,
//;0x03BC SCI6_RXI6
(fp)INT_Excep_SCI6_RXI6,
//;0x03C0 SCI6_TXI6
(fp)INT_Excep_SCI6_TXI6,
//;0x03C4 SCI6_TEI6
(fp)INT_Excep_SCI6_TEI6,
//;0x03C8 Reserved
(fp)0,
//;0x03CC Reserved
(fp)0,
//;0x03D0 Reserved
(fp)0,
//;0x03D4 Reserved
(fp)0,
//;0x03D8 RIIC0_ICEEI0
(fp)INT_Excep_RIIC0_ICEEI0,
//;0x03DC RIIC0_ICRXI0
(fp)INT_Excep_RIIC0_ICRXI0,
//;0x03E0 RIIC0_ICTXI0
(fp)INT_Excep_RIIC0_ICTXI0,
//;0x03E4 RIIC0_ICTEI0
(fp)INT_Excep_RIIC0_ICTEI0,
//;0x03E8 RIIC1_ICEEI1
(fp)INT_Excep_RIIC1_ICEEI1,
//;0x03EC RIIC1_ICRXI1
(fp)INT_Excep_RIIC1_ICRXI1,
//;0x03F0 RIIC1_ICTXI1
(fp)INT_Excep_RIIC1_ICTXI1,
//;0x03F4 RIIC1_ICTEI1
(fp)INT_Excep_RIIC1_ICTEI1,
//;0x03F8 Reserved
(fp)0,
//;0x03FC Reserved
(fp)0,
};
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/uC-Exosite/rdk_meta.c
|
<filename>uCOS-III-Ex6/uC-Exosite/rdk_meta.c
/******************************************************************************
* rdk_meta.c
*
* Helper functions for interacting with the RDK meta information flash block.
*
******************************************************************************/
#include "string.h"
#include "rdk_meta.h"
#include "flash_api_rx600.h"
static void erase_data_flash(unsigned char start, unsigned char end);
static void write_data_flash(unsigned char * writeBuffer, unsigned short numBytes, unsigned long writeAddress);
extern const uint32_t block_addresses[54]; // array of flash block addresses indexed by block #
/******************************************************************************
* void rdk_meta_init(void)
*
* This function simply enables flash for reading and writing.
*
******************************************************************************/
void rdk_meta_init(void)
{
R_FlashDataAreaAccess(0xFFFF, 0xFFFF);
}
/******************************************************************************
* rdk_meta_defaults(void)
*
* This function can be invoked by user code if it is found that the RDK meta
* information is not found in data flash.
* Note that this function read-modify-erase-writes meta location in flash. Any
* other information stored in the meta block will get wiped.
*
******************************************************************************/
void rdk_meta_defaults(void)
{
rdk_meta meta_info;
const unsigned char meta_server_ip[6] = {173,255,209,28,0,80};
memset(&meta_info, 0, sizeof(meta_info));
memcpy(meta_info.server, meta_server_ip, RDK_META_SERVER_SIZE);
strncpy(meta_info.mark, EXOMARK, RDK_META_MARK_SIZE);
rdk_meta_write((unsigned char *)&meta_info, sizeof(meta_info), (unsigned char *)RDK_META_LOCATION);
}
/******************************************************************************
* rdk_meta_write(unsigned char * write_buffer, unsigned char srcBytes, unsigned char * location)
*
* This function can be used to write a specific member of the meta structure
* into flash. It is a simple read-modify-erase-write routine.
* NOTE: This routine erases all of block 14 with every call, so use sparingly.
*
* For example, the following lines would update the CIK value:
* rdk_meta * meta_info = (rdk_meta *)RDK_META_LOCATION;
* write_meta("UPDATEWITH40CHARCIK", 40, (unsigned char *)meta_info->cik);
*
******************************************************************************/
unsigned char rdk_meta_write(unsigned char * write_buffer, unsigned short srcBytes, unsigned char * location)
{
rdk_meta meta_info;
unsigned long offset;
// make sure 'location' is within the rdk_meta flash region
if (
(unsigned long)(location) < (unsigned long)(RDK_META_LOCATION)
||
(unsigned long)(location + srcBytes) > (unsigned long)(RDK_META_LOCATION + RDK_META_SIZE)
) return 1;
offset = (unsigned long)location - (unsigned long)RDK_META_LOCATION;
memcpy((char *)((unsigned long)(&meta_info)), (char *)RDK_META_LOCATION, sizeof(meta_info)); // read our nv struct into RAM
memcpy((char *)((unsigned long)(&meta_info) + offset), (char *)write_buffer, srcBytes); // replace specific member info
erase_data_flash(14,14); //just erase block 14, the meta struct location
write_data_flash((unsigned char *)&meta_info, sizeof(meta_info), (unsigned long)RDK_META_LOCATION);
return 0;
}
/******************************************************************************
* void erase_data_flash(unsigned char start_block, unsigned char end_block)
*
* Erases data flash from start_block to end_block, inclusive. It locks upon
* error.
*
******************************************************************************/
static void erase_data_flash(unsigned char start_block, unsigned char end_block)
{
uint8_t ret = 0;
uint8_t loop_counter = 0, block_count = BLOCK_DB0 + start_block;
uint32_t address = 0x00000000;
/* Initialise a for loop to erase each of the data flash blocks */
for (loop_counter = start_block; loop_counter < end_block + 1; loop_counter++)
{
/* Fetch beginning address of DF block */
address = block_addresses[BLOCK_DB0 + loop_counter];
/* Erase data flash block */
ret |= R_FlashErase(block_count);
/* Check if data flash area is blank */
ret |= R_FlashDataAreaBlankCheck(address,BLANK_CHECK_ENTIRE_BLOCK);
/* Increment block counter */
block_count++;
}
/* Check Blank Checking */
ret |= R_FlashDataAreaBlankCheck(address,BLANK_CHECK_ENTIRE_BLOCK);
/* Halt in while loop when flash API errors detected */
while (ret);
}
/******************************************************************************
* void write_data_flash(unsigned char * writeBuffer, unsigned short numBytes, unsigned long writeAddress)
*
* Writes data flash with contents of writeBuffer for size of numBytes to
* location writeAddress. If contents are not fully verified, it locks.
*
******************************************************************************/
static void write_data_flash(unsigned char * writeBuffer, unsigned short numBytes, unsigned long writeAddress)
{
unsigned char ret = 0; // API error flag
unsigned char pad_buffer[256]; // data padding array and loop counter
unsigned short srcBytes = numBytes; // we have to save off size to use for compare later
/* Clear the contents of the flash write buffer array */
memset(pad_buffer, 0x00, 256);
/* Copy contents of the write buffer to the padding buffer */
memcpy((char *)pad_buffer, (char *)writeBuffer, numBytes);
/* Check if number of bytes is greater than 256 */
if (numBytes > 256)
{
/* Number of bytes to write too high, set error flag to 1 */
ret |= 1;
}
/* Check if number of bytes to write is a multiple of 8 */
else if (numBytes % 8u)
{
/* Pad the data to write so it makes up to the nearest multiple of 8 */
numBytes += 8u - (numBytes % 8u);
}
/* Halt in while loop when flash API errors detected */
while (ret);
/* Write contents of write buffer to data flash */
ret |= R_FlashWrite(writeAddress,(uint32_t)pad_buffer,numBytes);
/* Compare memory locations to verify written data */
ret |= memcmp(writeBuffer, (unsigned char *)writeAddress, srcBytes);
/* Halt in while loop when flash API errors detected */
while (ret);
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex5/app.c
|
/*
*********************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP.C
* By : FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_TCB AppTaskStartTCB;
static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
volatile CPU_INT08U AppCloudControlLedOn = 1;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppGraphLCD_Hdr(void);
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppTCPIP_Init (NET_ERR *perr);
void AppHTTPs_Init (void);
#endif
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
void AppProbe_Init (void);
#endif
void AppCloud_Init (CPU_BOOLEAN disableStatus);
#define EX_LED_ON(a) {if (AppCloudControlLedOn) LED_On(a); else LED_Off(a);}
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main (void)
{
OS_ERR err;
CPU_IntDis(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
App_OS_SetAllHooks();
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) 0,
(OS_PRIO ) APP_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while (1) {
;
}
return (0);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
CPU_INT08U i;
CPU_INT08U j;
OS_ERR err;
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
NET_ERR net_err;
#endif
(void)&p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */
#if (OS_CFG_STAT_TASK_EN > 0u)
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
AppProbe_Init(); /* Initialize uC/Probe modules */
#endif
/* Turn on 4 LEDs to show board is alive */
LED_On(14);
LED_On(5);
LED_On(8);
LED_On(11);
BSP_GraphLCD_Init();
AppGraphLCD_Hdr();
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */
if (net_err == NET_ERR_NONE) {
AppHTTPs_Init();
}
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
AppCloud_Init(0);
LED_Off(0); /* Turn all LEDs off */
while (DEF_ON) { /* Task body, always written as an infinite loop. */
for (i = 7; i <= 12; i++) {
EX_LED_ON(i);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
LED_Off(i);
}
for (i = 11; i > 7 ; i--) {
EX_LED_ON(i);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
LED_Off(i);
}
}
}
/*
*********************************************************************************************************
* AppGraphLCD_Hdr()
*********************************************************************************************************
*/
static void AppGraphLCD_Hdr (void)
{
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_LARGE);
BSP_GraphLCD_StringPos(0, 4, "Micrium");
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SMALL);
BSP_GraphLCD_StringPos(1, 5, "uC/OS-III");
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
BSP_GraphLCD_StringPos(2, 5, "uC/TCP-IP");
#endif
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/dhcp-c_cfg.h
|
<filename>uCOS-III-Lib/dhcp-c_cfg.h
/*
*********************************************************************************************************
* uC/DHCPc V2
* Dynamic Host Configuration Protocol Client
*
* (c) Copyright 2004-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/DHCPc is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* DHCP CLIENT CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : dhcp-c_cfg.h
* Version : V2.08.02
* Programmer(s) : SR
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* TASKS PRIORITIES
*********************************************************************************************************
*/
#define DHCPc_OS_CFG_TASK_PRIO 13
#define DHCPc_OS_CFG_TMR_TASK_PRIO 14
/*
*********************************************************************************************************
* STACK SIZES
* Size of the task stacks (# of OS_STK entries)
*********************************************************************************************************
*/
#define DHCPc_OS_CFG_TASK_STK_SIZE 640
#define DHCPc_OS_CFG_TMR_TASK_STK_SIZE 256
/*$PAGE*/
/*
*********************************************************************************************************
* DHCPc
*
* Note(s) : (1) Default port for DHCP server is 67, and default port for DHCP client is 68.
*
* (2) Configure DHCPc_CFG_BROADCAST_BIT_EN to DEF_ENABLED to instruct the contacted DHCP server
* to use broadcast packets instead of unicast ones. Used for TCP/IP stacks that cannot
* receive unicast packets when not fully configured. This is the case of the uC/TCPIP
* stack, so this define MUST be set to DEF_ENABLED when this DHCP client is used with the
* Micrium's uC/TCP-IP stack.
*
* (3) Configure DHCPc_CFG_MAX_NBR_IF to the maximum number of interface this DHCP client will
* be able to manage at a given time.
*
* (4) Once the DHCP server has assigned the client an address, the later may perform a final
* check prior to use this address in order to make sure it is not being used by another
* host on the network.
*********************************************************************************************************
*/
#define DHCPc_CFG_IP_PORT_SERVER 67 /* Configure DHCP server port (see Note #1). */
#define DHCPc_CFG_IP_PORT_CLIENT 68 /* Configure DHCP client port (see Note #1). */
#define DHCPc_CFG_MAX_RX_TIMEOUT_MS 2000 /* Maximum inactivity time (ms) on receive. */
#define DHCPc_CFG_BROADCAST_BIT_EN DEF_ENABLED /* Configure broadcast bit (see Note #2) :*/
/* DEF_DISABLED Broadcast bit NOT set */
/* DEF_ENABLED Broadcast bit set */
#define DHCPc_CFG_PARAM_REQ_TBL_SIZE 5 /* Configure requested parameter table size. */
#define DHCPc_CFG_MAX_NBR_IF 1 /* Configure maximum number of interface (see Note #3). */
#define DHCPc_CFG_ADDR_VALIDATE_EN DEF_ENABLED /* Configure final check on assigned address ... */
/* ... (see Note #4) : */
/* DEF_DISABLED Validation NOT performed */
/* DEF_ENABLED Validation performed */
#define DHCPc_CFG_DYN_LOCAL_LINK_ADDR_EN DEF_ENABLED /* Configure dynamic link-local address configuration : */
/* DEF_DISABLED local-link configuration DISABLED */
/* DEF_ENABLED local-link configuration ENABLED */
#define DHCPc_CFG_LOCAL_LINK_MAX_RETRY 2 /* Configure maximum number of retry to get a */
/* link-local address. */
/*
*********************************************************************************************************
* DHCPc ARGUMENT CHECK CONFIGURATION
*
* Note(s) : (1) Configure DHCPc_CFG_ARG_CHK_EXT_EN to enable/disable the DHCP client external argument
* check feature :
*
* (a) When ENABLED, ALL arguments received from any port interface provided by the developer
* or application are checked/validated.
*
* (b) When DISABLED, NO arguments received from any port interface provided by the developer
* or application are checked/validated.
*
* (2) Configure DHCPc_CFG_ARG_CHK_DBG_EN to enable/disable the DHCP client internal debug
* argument check feature :
*
* (a) When ENABLED, internal arguments are checked/validated to debug the DHCP client.
*
* (b) When DISABLED, NO internal arguments are checked/validated to debug the DHCP client.
*
* (3) Configure DHCPc_DBG_CFG_MEM_CLR_EN to enable/disable the DHCP client from clearing
* internal data structure memory buffers; a convenient feature while debugging.
*********************************************************************************************************
*/
/* Configure external argument check feature ... */
/* ... (see Note #1) : */
#define DHCPc_CFG_ARG_CHK_EXT_EN DEF_ENABLED
/* DEF_DISABLED Argument check DISABLED */
/* DEF_ENABLED Argument check ENABLED */
/* Configure internal argument check feature ... */
/* ... (see Note #2) : */
#define DHCPc_CFG_ARG_CHK_DBG_EN DEF_DISABLED
/* DEF_DISABLED Argument check DISABLED */
/* DEF_ENABLED Argument check ENABLED */
/* Configure memory clear feature (see Note #3) : */
#define DHCPc_DBG_CFG_MEM_CLR_EN DEF_ENABLED
/* DEF_DISABLED Data structure clears DISABLED */
/* DEF_ENABLED Data structure clears ENABLED */
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/net_dev_cfg.c
|
/*
*********************************************************************************************************
* uC/TCP-IP V2
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK DEVICE CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : net_dev_cfg.c
* Version : V2.11.02
* Programmer(s) : EHS
* FGK
* ITJ
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_DEV_CFG_MODULE
#include <net.h>
/*$PAGE*/
/*
*********************************************************************************************************
* EXAMPLE NETWORK INTERFACE / DEVICE CONFIGURATION
*
* Note(s) : (1) (a) Buffer & memory sizes & alignments configured in number of octets.
* (b) Data bus size configured in number of bits.
*
* (2) (a) All network buffer data area sizes MUST be configured greater than or equal to
* NET_BUF_DATA_SIZE_MIN.
* (b) Large transmit buffer data area sizes MUST be configured greater than or equal to
* small transmit buffer data area sizes.
* (c) Small transmit buffer data area sizes MAY need to be configured greater than or
* equal to the specific interface's minimum packet size.
*
* See also 'net_buf.c NetBuf_PoolCfgValidate() Note #3'
* & 'net_if_ether.c NetIF_Ether_BufPoolCfgValidate() Note #2'.
*
* (3) (a) MUST configure at least one (1) large receive buffer.
* (b) MUST configure at least one (1) transmit buffer, however, zero (0) large OR
* zero (0) small transmit buffers MAY be configured.
*
* See also 'net_buf.c NetBuf_PoolCfgValidate() Note #2'.
*
* (4) Some processors or devices may be more efficient & may even REQUIRE that buffer data areas
* align to specific CPU-word/octet address boundaries in order to successfully read/write
* data from/to devices. Therefore, it is recommended to align devices' buffer data areas to
* the processor's or device's data bus width.
*
* See also 'net_buf.h NETWORK BUFFER INDEX & SIZE DEFINES Note #2b'.
*
* (5) Positive offset from base receive/transmit index, if required by device (or driver) :
*
* (a) (1) Some device's may receive or buffer additional octets prior to the actual received
* packet. Thus, an offset may be required to ignore these additional octets :
*
* (A) If a device does NOT receive or buffer any additional octets prior to received
* packets, then the default offset of '0' SHOULD be configured.
*
* (B) However, if a device does receive or buffer additional octets prior to received
* packets, then configure the device's receive offset with the number of
* additional octets.
*
* See also 'net_buf.h NETWORK BUFFER INDEX & SIZE DEFINES Note #2b1A'.
*
* (2) Some device's/driver's may require additional octets prior to the actual transmit
* packet. Thus, an offset may be required to reserve additional octets :
*
* (A) If a device/driver does NOT require any additional octets prior to transmit
* packets, then the default offset of '0' SHOULD be configured.
*
* (B) However, if a device/driver does require additional octets prior to transmit
* packets, then configure the device's transmit offset with the number of
* additional octets.
*
* See also 'net_buf.h NETWORK BUFFER INDEX & SIZE DEFINES Note #2b1B'.
*
* (b) Since each network buffer data area allocates additional octets for its configured
* offset(s) [see 'net_if.c NetIF_BufPoolInit() Note #3'], the network buffer data
* area size does NOT need to be increased by the number of additional offset octets.
*
* (6) Flags to configure (optional) device features; bit-field flags logically OR'd :
*
* (a) NET_DEV_CFG_FLAG_NONE No device configuration flags selected.
*
* (b) NET_DEV_CFG_FLAG_SWAP_OCTETS Swap data octets [i.e. swap data words' high-order
* octet(s) with data words' low-order octet(s),
* & vice-versa] if required by device-to-CPU data
* bus wiring &/or CPU endian word order.
*
* (7) Network devices with receive descriptors MUST configure the number of receive buffers
* greater than the number of receive descriptors.
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* EXAMPLE NETWORK LOOPBACK INTERFACE CONFIGURATION
*********************************************************************************************************
*/
#if (NET_IF_CFG_LOOPBACK_EN == DEF_ENABLED)
const NET_IF_CFG_LOOPBACK NetIF_Cfg_Loopback = {
NET_IF_MEM_TYPE_MAIN, /* Desired receive buffer memory pool type : */
/* NET_IF_MEM_TYPE_MAIN buffers allocated from main memory */
/* NET_IF_MEM_TYPE_DEDICATED buffers allocated from (loopback's) dedicated memory */
1500u, /* Desired size of interface's large receive buffers (in octets) [see Note #2]. */
10u, /* Desired number of interface's large receive buffers [see Note #3a]. */
4u, /* Desired alignment of interface's receive buffers (in octets) [see Note #4]. */
0u, /* Desired offset from base receive index, if needed (in octets) [see Note #5a1]. */
NET_IF_MEM_TYPE_MAIN, /* Desired transmit buffer memory pool type : */
/* NET_IF_MEM_TYPE_MAIN buffers allocated from main memory */
/* NET_IF_MEM_TYPE_DEDICATED buffers allocated from (loopback's) dedicated memory */
1594u, /* Desired size of interface's large transmit buffers (in octets) [see Note #2]. */
10u, /* Desired number of interface's large transmit buffers [see Note #3b]. */
134u, /* Desired size of interface's small transmit buffers (in octets) [see Note #2]. */
10u, /* Desired number of interface's small transmit buffers [see Note #3b]. */
4u, /* Desired alignment of interface's transmit buffers (in octets) [see Note #4]. */
0u, /* Desired offset from base transmit index, if needed (in octets) [see Note #5a2]. */
0x00000000u, /* Base address of dedicated memory, if available. */
0u, /* Size of dedicated memory, if available (in octets). */
NET_DEV_CFG_FLAG_NONE, /* Desired option flags, if any (see Note #6). */
};
#endif /* End of network loopback configuration. */
/*$PAGE*/
/*
*********************************************************************************************************
* EXAMPLE ETHERNET DEVICE CONFIGURATION
*********************************************************************************************************
*/
#ifdef NET_IF_MODULE_ETHER_PRESENT
/* ------------------- EXAMPLE ETHERNET DEVICE #0 CONFIGURATION ------------------- */
const NET_DEV_CFG_ETHER NetDev_Cfg_RX_Ether_0 = {
NET_IF_MEM_TYPE_MAIN, /* Desired receive buffer memory pool type : */
/* NET_IF_MEM_TYPE_MAIN buffers allocated from main memory */
/* NET_IF_MEM_TYPE_DEDICATED buffers allocated from (device's) dedicated memory */
1520u, /* Desired size of device's large receive buffers (in octets) [see Note #2]. */
14u, /* Desired number of device's large receive buffers [see Note #3a]. */
16u, /* Desired alignment of device's receive buffers (in octets) [see Note #4]. */
0u, /* Desired offset from base receive index, if needed (in octets) [see Note #5a1].*/
NET_IF_MEM_TYPE_MAIN, /* Desired transmit buffer memory pool type : */
/* NET_IF_MEM_TYPE_MAIN buffers allocated from main memory */
/* NET_IF_MEM_TYPE_DEDICATED buffers allocated from (device's) dedicated memory */
1614u, /* Desired size of device's large transmit buffers (in octets) [see Note #2]. */
3u, /* Desired number of device's large transmit buffers [see Note #3b]. */
256u, /* Desired size of device's small transmit buffers (in octets) [see Note #2]. */
4u, /* Desired number of device's small transmit buffers [see Note #3b]. */
16u, /* Desired alignment of device's transmit buffers (in octets) [see Note #4]. */
0u, /* Desired offset from base transmit index, if needed (in octets) [see Note #5a2].*/
0x00000000u, /* Base address of dedicated memory, if available. */
0u, /* Size of dedicated memory, if available (in octets). */
NET_DEV_CFG_FLAG_NONE, /* Desired option flags, if any (see Note #6). */
7u, /* Desired number of device's receive descriptors (see Note #7). */
7u, /* Desired number of device's transmit descriptors. */
0x000C0000u, /* Base address of device's hardware/registers. */
0u, /* Size of device's data bus (in bits), if available. */
"00:30:55:08:80:00", /* Desired device hardware address; may be NULL address or string ... */
/* ... if device hardware address configured or set at run-time. */
};
const NET_PHY_CFG_ETHER NetPhy_Cfg_Generic_0 = {
1u, /* Phy bus address. */
NET_PHY_BUS_MODE_RMII, /* Phy bus mode. */
NET_PHY_TYPE_EXT, /* Phy type. */
NET_PHY_SPD_AUTO, /* Auto-Negotiation determines link speed. */
NET_PHY_DUPLEX_AUTO, /* Auto-Negotiation determines link duplex. */
};
#endif /* End of Ethernet device configuration. */
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/audio.c
|
<reponame>nbarjolin/micrium_gnurx_cloud<filename>uCOS-III-Ex6/audio.c
/*
*********************************************************************************************************
* AUDIO APPLICATION
*
* (c) Copyright 2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* AUDIO MANAGEMENT
* Filename : audio.c
* Version : V1.02
* Programmer(s) : FT
* FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <audio.h>
#include <os.h>
#include <bsp.h>
#include <iodefine.h>
#include <r_adpcm.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define AUDIO_PWM_BITS_PER_SAMPLE 16u
/*
*********************************************************************************************************
* AUDIO STREAM STATE
*********************************************************************************************************
*/
typedef enum audio_stream_state {
AUDIO_STREAM_CLOSED = 1,
AUDIO_STREAM_OPENED,
AUDIO_STREAM_CLOSING
} AUDIO_STREAM_STATE;
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef struct audio_buf_q {
AUDIO_BUF *HeadPtr;
AUDIO_BUF *TailPtr;
CPU_SIZE_T Entries;
} AUDIO_BUF_Q;
typedef struct dtc_vector { /* Little-endian full-address mode. */
CPU_INT16U Reserved;
CPU_REG08 MRB;
CPU_REG08 MRA;
volatile CPU_VOID *SAR;
volatile CPU_VOID *DAR;
CPU_REG16 CRB;
CPU_REG16 CRA;
} DTC_VECTOR;
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
/* --------------- STREAM INFO VARIABLES -------------- */
static AUDIO_STREAM_STATE AudioStream_State; /* Stream open status. */
static CPU_BOOLEAN AudioStream_Buffering; /* Stream buffering. */
static CPU_INT08U AudioStream_BitsPerSample; /* Stream bits per sample. */
static CPU_INT08U AudioStream_Channels; /* Stream number of channels. */
static CPU_INT32U AudioStream_SampleFreq; /* Stream sample frequency. */
static AUDIO_STREAM_FMT AudioStream_Fmt; /* Stream format. */
static CPU_INT16U AudioStream_Vol; /* Stream volume. */
static CPU_INT16U AudioStream_PWMPer; /* Stream PWM period. */
static OS_SEM AudioStream_ClosedSem; /* Stream closed semaphore. */
/* -------------- AUDIO BUFFER MANAGEMENT ------------- */
static OS_SEM AudioBuf_Sem; /* Audio buffer semaphore. */
static MEM_POOL AudioBuf_Pool; /* Audio buffer header memory pool. */
static MEM_POOL AudioBuf_DataPool; /* Audio buffer data area memory pool. */
static AUDIO_BUF_Q AudioBuf_Q; /* Audio buffer queue to be processed. */
static CPU_INT32U AudioBuf_QTh; /* Audio buffer queue buffering threshold. */
static AUDIO_BUF *AudioBuf_Aux; /* Audio buffer to de-interleave stereo or dec ADPCM. */
static adpcm_env AudioADPCM_Env; /* ADPCM decoder environment structure. */
/* DTC Vectors section MUST be aligned to 2^12 bytes. */
#if __GNUC__
#define DTC_VECTOR_TBL __attribute__ ((section (".dtc_vector_tbl")))
#else
#define DTC_VECTOR_TBL
#pragma section dtc_vector_tbl
#endif
static DTC_VECTOR *DTC_VectorTbl[256] DTC_VECTOR_TBL;
#if __GNUC__
#define DTC_VECTORS __attribute__ ((section (".dtc_vectors")))
#else
#define DTC_VECTORS
#pragma section dtc_vectors
#endif
static DTC_VECTOR DTC_VectorNull DTC_VECTORS;
static DTC_VECTOR DTC_VectorChA DTC_VECTORS;
static DTC_VECTOR DTC_VectorChB DTC_VECTORS;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void PWM_Init (void);
static void PWM_Cfg (CPU_INT16U pwm_per,
CPU_INT08U skip_cnt);
static void DTC_Init (void);
static void DTC_En (void);
static void DTC_Dis (void);
static void DTC_IntAck (void);
static void DTC_SetXfer(AUDIO_BUF *p_buf);
/*
*********************************************************************************************************
* Audio_Init()
*
* Description : Initialize Audio interface:
*
* (1) Initialize stream configuration to the default value.
*
* (2) Create memory pool for audio stream buffer.
*
* (3) Create a stream buffer semaphore for signaling.
*
* (4) Configure hardware.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if audio module initialized successfully.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN Audio_Init (void)
{
LIB_ERR lib_err;
OS_ERR os_err;
CPU_SIZE_T octects_reqd;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
AudioStream_State = AUDIO_STREAM_CLOSED;
AudioStream_Buffering = DEF_FALSE;
AudioStream_BitsPerSample = 0u;
AudioStream_Fmt = AUDIO_STREAM_FMT_NONE;
AudioStream_Vol = 0u;
AudioStream_PWMPer = 0u;
AudioBuf_Q.HeadPtr = (AUDIO_BUF *)0;
AudioBuf_Q.TailPtr = (AUDIO_BUF *)0;
AudioBuf_Q.Entries = 0u;
AudioBuf_QTh = 0u;
AudioBuf_Aux = (AUDIO_BUF *)0;
CPU_CRITICAL_EXIT();
Mem_PoolCreate((MEM_POOL *)&AudioBuf_Pool,
(void *) 0,
(CPU_SIZE_T ) 0u,
(CPU_SIZE_T ) AUDIO_CFG_BUF_NBR,
(CPU_SIZE_T ) sizeof(AUDIO_BUF),
(CPU_SIZE_T ) sizeof(CPU_ALIGN),
(CPU_SIZE_T *)&octects_reqd,
(LIB_ERR *)&lib_err);
if (lib_err != LIB_MEM_ERR_NONE) {
return (DEF_FAIL);
}
Mem_PoolCreate((MEM_POOL *)&AudioBuf_DataPool,
(void *) 0,
(CPU_SIZE_T ) 0u,
(CPU_SIZE_T ) AUDIO_CFG_BUF_NBR,
(CPU_SIZE_T ) AUDIO_CFG_BUF_SIZE,
(CPU_SIZE_T ) sizeof(CPU_ALIGN),
(CPU_SIZE_T *)&octects_reqd,
(LIB_ERR *)&lib_err);
if (lib_err != LIB_MEM_ERR_NONE) {
return (DEF_FAIL);
}
OSSemCreate((OS_SEM *)&AudioBuf_Sem,
(CPU_CHAR *)"Audio Buffer Signal",
(OS_SEM_CTR) AUDIO_CFG_BUF_NBR,
(OS_ERR *)&os_err);
if (os_err != OS_ERR_NONE) {
return (DEF_FAIL);
}
OSSemCreate((OS_SEM *)&AudioStream_ClosedSem,
(CPU_CHAR *)"Audio Stream Closed Signal",
(OS_SEM_CTR) 0u,
(OS_ERR *)&os_err);
if (os_err != OS_ERR_NONE) {
return (DEF_FAIL);
}
DTC_Init();
PWM_Init();
PWM_Cfg(256u, 4u);
return (DEF_OK);
}
/*
*********************************************************************************************************
* AudioStream_Open()
*
* Description : Open an audio stream.
*
* Argument(s) : fmt Audio stream format.
*
* ch Number of channels.
*
* sample_freq Sample frequency.
*
* p_samples_buf Pointer to a variable to return the maximum possible number of samples
* the buffer data area can hold (see Note #2).
*
* Return(s) : DEF_OK if audio stream open without errors.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) 'Audio_StreamOpen()' & 'Audio_StreamClose()' must be called in pairs.
*
* (2) Maximum possible number of samples for total number of channels of the audio stream.
*********************************************************************************************************
*/
CPU_BOOLEAN AudioStream_Open (CPU_INT08U fmt,
CPU_INT08U ch,
CPU_INT32U sample_freq,
CPU_SIZE_T *p_samples_buf)
{
CPU_INT08U bits_per_sample;
CPU_INT32U freq;
CPU_INT32U pwm_per;
CPU_INT32U skip_cnt;
CPU_INT32U max_buf;
CPU_INT32U q_th;
CPU_SR_ALLOC();
if (p_samples_buf == (CPU_SIZE_T *)0) {
return (DEF_FAIL);
}
switch (fmt) {
case AUDIO_STREAM_FMT_04_ADPCM:
bits_per_sample = 4u;
if (ch != 1u) {
return (DEF_FAIL);
}
break;
case AUDIO_STREAM_FMT_08_UNSIGNED:
bits_per_sample = 8u;
break;
case AUDIO_STREAM_FMT_16_UNSIGNED:
case AUDIO_STREAM_FMT_16_SIGNED:
bits_per_sample = 16u;
break;
default:
return (DEF_FAIL);
}
switch (ch) {
case 1u:
case 2u:
break;
default:
return (DEF_FAIL);
}
switch (sample_freq) {
case 8000u:
case 11025u:
case 16000u:
case 22050u:
case 24000u:
case 32000u:
case 44100u:
case 48000u:
break;
default:
return (DEF_FAIL);
}
freq = BSP_CPU_PerClkFreq();
/* Min PWM 8-bit resolution, twice sample frequency. */
if ((sample_freq * 256u * 2u) > freq) {
return (DEF_FAIL);
}
skip_cnt = freq / (sample_freq * 256u * 2u);
if (skip_cnt > 8u) {
skip_cnt = 8u;
}
pwm_per = freq / (sample_freq * skip_cnt); /* PWM period. */
if (pwm_per > DEF_INT_16U_MAX_VAL) {
return (DEF_FAIL);
}
if (pwm_per < DEF_INT_08U_MAX_VAL) {
return (DEF_FAIL);
}
/* Compute buf cnt for cfg'd threshold. */
q_th = (sample_freq * AUDIO_CFG_BUF_TH * ch * bits_per_sample +
(DEF_TIME_NBR_mS_PER_SEC * AUDIO_CFG_BUF_SIZE * DEF_OCTET_NBR_BITS) / 2u) /
(DEF_TIME_NBR_mS_PER_SEC * AUDIO_CFG_BUF_SIZE * DEF_OCTET_NBR_BITS);
if ((ch == 2u) ||
(fmt == AUDIO_STREAM_FMT_04_ADPCM)) {
max_buf = AUDIO_CFG_BUF_NBR - 1u; /* Reserve one auxiliary buffer. */
} else {
max_buf = AUDIO_CFG_BUF_NBR;
}
if (q_th < 1u) {
q_th = 1u;
} else if (q_th > max_buf) {
q_th = max_buf;
}
CPU_CRITICAL_ENTER();
if (AudioStream_State != AUDIO_STREAM_CLOSED) {
CPU_CRITICAL_EXIT();
return (DEF_FAIL);
}
AudioStream_State = AUDIO_STREAM_OPENED;
AudioStream_BitsPerSample = bits_per_sample;
AudioStream_SampleFreq = sample_freq;
AudioStream_Channels = ch;
AudioStream_Fmt = fmt;
AudioStream_PWMPer = pwm_per;
AudioStream_Buffering = DEF_TRUE;
AudioBuf_QTh = q_th;
CPU_CRITICAL_EXIT();
*p_samples_buf = AUDIO_CFG_BUF_SIZE /
((AUDIO_PWM_BITS_PER_SAMPLE + DEF_OCTET_NBR_BITS - 1u) /
DEF_OCTET_NBR_BITS);
/* Alloc aux buf for stereo or ADPCM. */
if ((ch == 2u) ||
(fmt == AUDIO_STREAM_FMT_04_ADPCM)) {
AudioBuf_Aux = AudioBuf_Get();
} else {
AudioBuf_Aux = (AUDIO_BUF *)0;
}
if (fmt == AUDIO_STREAM_FMT_04_ADPCM) {
R_adpcm_initDec(&AudioADPCM_Env);
}
PWM_Cfg(pwm_per, skip_cnt);
return (DEF_OK);
}
/*
*********************************************************************************************************
* AudioStream_VolSet()
*
* Description : Set volume of an audio stream.
*
* Argument(s) : vol Volume percentage: 0..100%
*
* Return(s) : DEF_OK if audio stream volume set successfully.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN AudioStream_VolSet (CPU_INT08U vol)
{
CPU_SR_ALLOC();
if (vol > 100u) {
return (DEF_FAIL);
}
CPU_CRITICAL_ENTER();
AudioStream_Vol = vol;
CPU_CRITICAL_EXIT();
return (DEF_OK);
}
/*
*********************************************************************************************************
* AudioStream_Close()
*
* Description : Close an audio stream.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if audio stream closed successfully.
*
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN AudioStream_Close (void)
{
OS_ERR os_err;
CPU_SR_ALLOC();
if (AudioStream_State != AUDIO_STREAM_OPENED) {
return (DEF_FAIL);
}
CPU_CRITICAL_ENTER();
AudioStream_BitsPerSample = 0u;
AudioStream_SampleFreq = 0u;
#if 0 /* Used by DTC_SetXfer() for right-channel buf offset. */
AudioStream_Channels = 0u;
#endif
AudioStream_Fmt = 0u;
if (AudioBuf_Q.Entries > 0u) {
AudioStream_State = AUDIO_STREAM_CLOSING;
if (AudioStream_Buffering == DEF_TRUE) {
AudioStream_Buffering = DEF_FALSE;
DTC_SetXfer(AudioBuf_Q.HeadPtr);
CPU_CRITICAL_EXIT();
DTC_En();
} else {
CPU_CRITICAL_EXIT();
}
OSSemPend((OS_SEM *)&AudioStream_ClosedSem,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
} else {
AudioStream_State = AUDIO_STREAM_CLOSED;
DTC_Dis();
CPU_CRITICAL_EXIT();
}
if (AudioBuf_Aux != (AUDIO_BUF *)0) {
AudioBuf_Abort(AudioBuf_Aux);
AudioBuf_Aux = (AUDIO_BUF *)0;
}
return (DEF_OK);
}
/*
*********************************************************************************************************
* AudioBuf_Get()
*
* Description : Get an audio stream buffer.
*
* Argument(s) : none.
*
* Return(s) : Pointer to audio stream buffer structure, if NO error(s).
*
* Pointer to NULL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) This function blocks until a buffer is available.
*********************************************************************************************************
*/
AUDIO_BUF *AudioBuf_Get (void)
{
AUDIO_BUF *p_buf;
void *p_data;
OS_ERR os_err;
LIB_ERR lib_err;
if (AudioStream_State != AUDIO_STREAM_OPENED) {
return ((AUDIO_BUF *)0);
}
OSSemPend((OS_SEM *)&AudioBuf_Sem,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
p_buf = (AUDIO_BUF *)Mem_PoolBlkGet((MEM_POOL *)&AudioBuf_Pool,
(CPU_SIZE_T) sizeof(AUDIO_BUF),
(LIB_ERR *)&lib_err);
if (lib_err != LIB_MEM_ERR_NONE) {
return ((AUDIO_BUF *)0);
}
p_data = (void *)Mem_PoolBlkGet((MEM_POOL *)&AudioBuf_DataPool,
(CPU_SIZE_T) AUDIO_CFG_BUF_SIZE,
(LIB_ERR *)&lib_err);
if (lib_err != LIB_MEM_ERR_NONE) {
Mem_PoolBlkFree((MEM_POOL *)&AudioBuf_Pool,
(void *) p_buf,
(LIB_ERR *)&lib_err);
return ((AUDIO_BUF *)0);
}
p_buf->DataPtr = p_data;
p_buf->Samples = 0u;
p_buf->NextPtr = (AUDIO_BUF *)0;
return (p_buf);
}
/*
*********************************************************************************************************
* AudioBuf_Abort()
*
* Description : Abort an audio stream buffer.
*
* Argument(s) : p_buf Pointer to audio stream buffer.
*
* Return(s) : none.
*
* Caller(s) : Application,
* AudioBuf_Enqueue(),
* AudioCallbackHandler().
*
* Note(s) : none.
*********************************************************************************************************
*/
void AudioBuf_Abort (AUDIO_BUF *p_buf)
{
LIB_ERR lib_err;
OS_ERR os_err;
if (p_buf == (AUDIO_BUF *)0) {
return;
}
/* Rtn buf hdr & data area to memory pools. */
Mem_PoolBlkFree((MEM_POOL *)&AudioBuf_DataPool,
(void *) p_buf->DataPtr,
(LIB_ERR *)&lib_err);
if (lib_err != LIB_MEM_ERR_NONE) {
return;
}
Mem_PoolBlkFree((MEM_POOL *)&AudioBuf_Pool,
(void *) p_buf,
(LIB_ERR *)&lib_err);
if (lib_err != LIB_MEM_ERR_NONE) {
return;
}
OSSemPost(&AudioBuf_Sem, /* Post to the stream buffer semaphore. */
OS_OPT_POST_1,
&os_err);
}
/*
*********************************************************************************************************
* AudioBuf_Enqueue()
*
* Description : Enqueue audio stream buffer to the audio management task.
*
* Argument(s) : p_buf Pointer to audio stream buffer.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void AudioBuf_Enqueue (AUDIO_BUF *p_buf)
{
AUDIO_BUF *p_last;
CPU_INT08U *p_buf_data_08;
CPU_INT16U *p_buf_data_16;
CPU_INT16U *p_buf_aux_16;
CPU_INT16S *p_sample_aux_16;
CPU_SIZE_T buf_ix;
CPU_SIZE_T buf_alt_ix;
CPU_SIZE_T buf_cnt;
CPU_INT16S sample_16;
CPU_SIZE_T nbr_samples;
CPU_INT16U vol;
CPU_INT16S dec;
CPU_SR_ALLOC();
if (p_buf == (AUDIO_BUF *)0) {
return;
}
if (AudioStream_State != AUDIO_STREAM_OPENED) { /* If audio stream is not open ... */
AudioBuf_Abort(p_buf); /* ... rtn buf to memory pool. */
return;
}
if (p_buf->Samples == 0) { /* If no samples to enqueue ... */
AudioBuf_Abort(p_buf); /* ... rtn buf to memory pool. */
return;
}
switch (AudioStream_Fmt) {
case AUDIO_STREAM_FMT_04_ADPCM:
p_buf_data_08 = (CPU_INT08U *)p_buf->DataPtr;
p_buf_data_16 = (CPU_INT16U *)p_buf->DataPtr;
p_sample_aux_16 = (CPU_INT16S *)AudioBuf_Aux->DataPtr;
vol = (DEF_INT_16U_MAX_VAL * 100u + 9 * (AudioStream_PWMPer * AudioStream_Vol) / 10) /
(AudioStream_PWMPer * AudioStream_Vol);
nbr_samples = p_buf->Samples;
switch (AudioStream_Channels) {
case 1u:
R_adpcm_refreshDec(p_buf_data_08,
p_sample_aux_16,
&AudioADPCM_Env);
dec = R_adpcm_decode(nbr_samples, &AudioADPCM_Env);
if (dec == 0) {
for (buf_ix = 0u; buf_ix < nbr_samples; buf_ix++) {
sample_16 = p_sample_aux_16[buf_ix];
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
}
} else {
Mem_Clr(p_buf->DataPtr, nbr_samples * sizeof(CPU_INT16U));
}
break;
default:
AudioBuf_Abort(p_buf); /* Rtn buf to memory pool on unsupported fmt. */
return;
}
break;
case AUDIO_STREAM_FMT_08_UNSIGNED:
p_buf_data_08 = (CPU_INT08U *)p_buf->DataPtr;
p_buf_data_16 = (CPU_INT16U *)p_buf->DataPtr;
vol = (CPU_INT32U)(AudioStream_PWMPer * AudioStream_Vol) / DEF_INT_08U_MAX_VAL;
switch (AudioStream_Channels) {
case 1u:
nbr_samples = p_buf->Samples;
buf_ix = nbr_samples - 1u;
for (buf_cnt = 0u; buf_cnt < nbr_samples; buf_cnt++) {
sample_16 = p_buf_data_08[buf_ix];
sample_16 -= 128;
sample_16 *= vol;
sample_16 /= 100;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
buf_ix--;
}
break;
case 2u:
p_buf_aux_16 = (CPU_INT16U *)AudioBuf_Aux->DataPtr;
nbr_samples = p_buf->Samples / 2u;
for (buf_ix = 0u, buf_alt_ix = 0u; buf_ix < nbr_samples; buf_ix++, buf_alt_ix += 2u) {
/* Right samples. */
sample_16 = p_buf_data_08[buf_alt_ix + 1u];
sample_16 -= 128;
sample_16 *= vol;
sample_16 /= 100;
sample_16 += AudioStream_PWMPer / 2;
p_buf_aux_16[buf_ix] = sample_16;
/* Left samples. */
sample_16 = p_buf_data_08[buf_alt_ix];
sample_16 -= 128;
sample_16 *= vol;
sample_16 /= 100;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
}
Mem_Copy((CPU_INT08U *)p_buf->DataPtr + (AUDIO_CFG_BUF_SIZE / 2u),
p_buf_aux_16,
nbr_samples * sizeof(CPU_INT16U));
break;
default:
AudioBuf_Abort(p_buf); /* Rtn buf to memory pool on unsupported fmt. */
return;
}
break;
case AUDIO_STREAM_FMT_16_UNSIGNED:
p_buf_data_16 = (CPU_INT16U *)p_buf->DataPtr;
vol = (DEF_INT_16U_MAX_VAL * 100u + 9 * (AudioStream_PWMPer * AudioStream_Vol) / 10) /
(AudioStream_PWMPer * AudioStream_Vol);
switch (AudioStream_Channels) {
case 1u:
nbr_samples = p_buf->Samples;
for (buf_ix = 0u; buf_ix < nbr_samples; buf_ix++) {
MEM_VAL_COPY_GET_INT16U_LITTLE(&sample_16, &p_buf_data_16[buf_ix]);
sample_16 -= 32768;
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
}
break;
case 2u:
p_buf_aux_16 = (CPU_INT16U *)AudioBuf_Aux->DataPtr;
nbr_samples = p_buf->Samples / 2u;
for (buf_ix = 0u, buf_alt_ix = 0u; buf_ix < nbr_samples; buf_ix++, buf_alt_ix += 2u) {
/* Right samples. */
MEM_VAL_COPY_GET_INT16U_LITTLE(&sample_16, &p_buf_data_16[buf_alt_ix + 1u]);
sample_16 -= 32768;
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_aux_16[buf_ix] = sample_16;
/* Left samples. */
MEM_VAL_COPY_GET_INT16U_LITTLE(&sample_16, &p_buf_data_16[buf_alt_ix]);
sample_16 -= 32768;
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
}
Mem_Copy((CPU_INT08U *)p_buf->DataPtr + (AUDIO_CFG_BUF_SIZE / 2u),
p_buf_aux_16,
nbr_samples * sizeof(CPU_INT16U));
break;
default:
AudioBuf_Abort(p_buf); /* Rtn buf to memory pool on unsupported fmt. */
return;
}
break;
case AUDIO_STREAM_FMT_16_SIGNED:
p_buf_data_16 = (CPU_INT16U *)p_buf->DataPtr;
vol = (DEF_INT_16U_MAX_VAL * 100u + 9 * (AudioStream_PWMPer * AudioStream_Vol) / 10) /
(AudioStream_PWMPer * AudioStream_Vol);
switch (AudioStream_Channels) {
case 1u:
nbr_samples = p_buf->Samples;
for (buf_ix = 0u; buf_ix < nbr_samples; buf_ix++) {
MEM_VAL_COPY_GET_INT16U_LITTLE(&sample_16, &p_buf_data_16[buf_ix]);
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
}
break;
case 2u:
p_buf_aux_16 = (CPU_INT16U *)AudioBuf_Aux->DataPtr;
nbr_samples = p_buf->Samples / 2u;
for (buf_ix = 0u, buf_alt_ix = 0u; buf_ix < nbr_samples; buf_ix++, buf_alt_ix += 2u) {
/* Right samples. */
MEM_VAL_COPY_GET_INT16U_LITTLE(&sample_16, &p_buf_data_16[buf_alt_ix + 1u]);
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_aux_16[buf_ix] = sample_16;
/* Left samples. */
MEM_VAL_COPY_GET_INT16U_LITTLE(&sample_16, &p_buf_data_16[buf_alt_ix]);
sample_16 /= vol;
sample_16 += AudioStream_PWMPer / 2;
p_buf_data_16[buf_ix] = sample_16;
}
Mem_Copy((CPU_INT08U *)p_buf->DataPtr + (AUDIO_CFG_BUF_SIZE / 2u),
p_buf_aux_16,
nbr_samples * sizeof(CPU_INT16U));
break;
default:
AudioBuf_Abort(p_buf); /* Rtn buf to memory pool on unsupported fmt. */
return;
}
break;
default:
AudioBuf_Abort(p_buf); /* Rtn buf to memory pool on unsupported fmt. */
return;
}
CPU_CRITICAL_ENTER();
if (AudioBuf_Q.Entries == 0u) { /* If queue is empty */
AudioBuf_Q.HeadPtr = p_buf;
} else { /* Put element at the end of queue. */
p_last = AudioBuf_Q.TailPtr;
p_last->NextPtr = p_buf;
}
AudioBuf_Q.TailPtr = p_buf;
AudioBuf_Q.Entries++;
if ((AudioStream_Buffering == DEF_TRUE) &&
(AudioBuf_Q.Entries > AudioBuf_QTh)) {
AudioStream_Buffering = DEF_FALSE;
p_buf = AudioBuf_Q.HeadPtr;
CPU_CRITICAL_EXIT();
/* Initialize DMA transfer. */
DTC_SetXfer(p_buf);
DTC_En();
} else {
CPU_CRITICAL_EXIT();
}
}
/*
*********************************************************************************************************
* AudioUtil_TimeToSamples()
*
* Description : Convert milliseconds to number of samples.
*
* Argument(s) : time Duration in miliseconds.
*
* Return(s) : Number of samples.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_SIZE_T AudioUtil_TimeToSamples (CPU_INT32U time)
{
CPU_SIZE_T nbr_samples;
if (AudioStream_State != AUDIO_STREAM_OPENED) {
return (0u);
}
nbr_samples = (AudioStream_SampleFreq * time) /
DEF_TIME_NBR_mS_PER_SEC;
return (nbr_samples);
}
/*
*********************************************************************************************************
* AudioUtil_TimeToOctets()
*
* Description : Convert milliseconds to number of octets.
*
* Argument(s) : time Duration in miliseconds.
*
* Return(s) : Number of octets.
*
* Caller(s) : Application.
*
* Note(s) : (1) Conversion based on single-channel.
*********************************************************************************************************
*/
CPU_SIZE_T AudioUtil_TimeToOctets (CPU_INT32U time)
{
CPU_SIZE_T nbr_samples;
CPU_SIZE_T nbr_octets;
if (AudioStream_State != AUDIO_STREAM_OPENED) {
return (0u);
}
nbr_samples = (AudioStream_SampleFreq * time) /
DEF_TIME_NBR_mS_PER_SEC;
nbr_octets = nbr_samples *
((AudioStream_BitsPerSample + DEF_OCTET_NBR_BITS - 1u) /
DEF_OCTET_NBR_BITS);
return (nbr_octets);
}
/*
*********************************************************************************************************
* AudioUtil_SamplesToOctets()
*
* Description : Convert number of samples to number of octets.
*
* Argument(s) : nbr_samples Number of samples.
*
* Return(s) : Number of octets.
*
* Caller(s) : Application.
*
* Note(s) : (1) Conversion based on single-channel.
*********************************************************************************************************
*/
CPU_SIZE_T AudioUtil_SamplesToOctets (CPU_SIZE_T nbr_samples)
{
CPU_SIZE_T nbr_octets;
if (AudioStream_State != AUDIO_STREAM_OPENED) {
return (0u);
}
nbr_octets = (nbr_samples * AudioStream_BitsPerSample) /
DEF_OCTET_NBR_BITS;
return (nbr_octets);
}
/*
*********************************************************************************************************
* AudioUtil_OctetsToSamples()
*
* Description : Convert from number of octets to number of samples.
*
* Argument(s) : nbr_octets Number of octets.
*
* Return(s) : Number of samples.
*
* Caller(s) : Application.
*
* Note(s) : (1) Conversion based on single-channel.
*********************************************************************************************************
*/
CPU_SIZE_T AudioUtil_OctetsToSamples (CPU_SIZE_T nbr_octets)
{
CPU_SIZE_T nbr_samples;
if (AudioStream_State != AUDIO_STREAM_OPENED) {
return (0u);
}
nbr_samples = (DEF_OCTET_NBR_BITS * nbr_octets) /
AudioStream_BitsPerSample;
return (nbr_samples);
}
/*
*********************************************************************************************************
* PWM_Init()
*
* Description : Initialize PWM controller.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void PWM_Init (void)
{
MSTP(MTUB) = 0u; /* Start MTU6 thru MTU11. */
MTUB.TSTR.BIT.CST3 = 0u; /* Disable MTU9. */
MTUB.TSTR.BIT.CST2 = 0u; /* Disable MTU8. */
#if (AUDIO_CFG_SSM2377_EN > 0u)
PORTA.DR.BYTE &= ~DEF_BIT_00; /* PA: Audio (PA0) output start at LOW. */
PORTA.DDR.BYTE |= DEF_BIT_00; /* PA: Audio (PA0) set as output. */
#else
PORTA.DR.BYTE &= ~(DEF_BIT_06 | DEF_BIT_07); /* PA: Audio (PA6-PA7) outputs start at LOW. */
PORTA.DDR.BYTE |= DEF_BIT_06 | DEF_BIT_07; /* PA: Audio (PA6-PA7) set as outputs. */
#endif
MTUB.TSYR.BIT.SYNC3 = 1u; /* Sync MTU9 & ... */
#if (AUDIO_CFG_SSM2377_EN > 0u)
MTUB.TSYR.BIT.SYNC0 = 1u; /* ... MTU6. */
#else
MTUB.TSYR.BIT.SYNC2 = 1u; /* ... MTU8. */
#endif
/* ------------- MTU9/PWM SWITCHING PERIOD ------------ */
MTU9.TCR.BIT.TPSC = 0u; /* 0 = PCLK */
MTU9.TCR.BIT.CKEG = 0u; /* 0 = Count at rising edge */
MTU9.TCR.BIT.CCLR = 1u; /* 1 = TCNT cleared by TGRA compare match */
MTU9.TGRA = 256u - 1u;
MTUB.TITCR.BIT.T3ACOR = 0u;
MTUB.TITCR.BIT.T3AEN = 0u;
#if (AUDIO_CFG_SSM2377_EN > 0u) /* ---------------- MTU6/PWM DUTY CYCLE --------------- */
MTU6.TCR.BIT.TPSC = 0u; /* 0 = PCLK */
MTU6.TCR.BIT.CKEG = 0u; /* 0 = Count at rising edge */
MTU6.TCR.BIT.CCLR = 3u; /* 3 = TCNT cleared by sync: MTU9 */
MTU6.TMDR.BIT.MD = 3u; /* 3 = PWM mode 2 */
MTU6.TGRA = 0u;
MTUB.TSTR.BIT.CST3 = 1u; /* Enable MTU9. */
MTUB.TSTR.BIT.CST0 = 1u; /* Enable MTU6. */
/* Output pins are negated */
MTU6.TIORH.BIT.IOA = 5u; /* 5 = initial output high, low output at compare match */
#else /* ---------------- MTU8/PWM DUTY CYCLE --------------- */
MTU8.TCR.BIT.TPSC = 0u; /* 0 = PCLK */
MTU8.TCR.BIT.CKEG = 0u; /* 0 = Count at rising edge */
MTU8.TCR.BIT.CCLR = 3u; /* 3 = TCNT cleared by sync: MTU9 */
MTU8.TMDR.BIT.MD = 3u; /* 3 = PWM mode 2 */
MTU8.TGRA = 0u;
MTU8.TGRB = 0u;
MTUB.TSTR.BIT.CST3 = 1u; /* Enable MTU9. */
MTUB.TSTR.BIT.CST2 = 1u; /* Enable MTU8. */
/* Output pins are negated */
MTU8.TIOR.BIT.IOB = 5u; /* 5 = initial output high, low output at compare match */
MTU8.TIOR.BIT.IOA = 5u; /* 5 = initial output high, low output at compare match */
#endif
}
/*
*********************************************************************************************************
* PWM_Cfg()
*
* Description : Configure PWM controller.
*
* Argument(s) : pwm_per PWM period.
*
* skip_cnt Interrupt skip count.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) Slow ramp to 50% duty cycle to reduce 'clicks' between different audio stream formats.
*********************************************************************************************************
*/
static void PWM_Cfg (CPU_INT16U pwm_per,
CPU_INT08U skip_cnt)
{
CPU_INT16U half;
CPU_INT16U old_per;
CPU_INT16U init_a;
CPU_INT16U old_a;
CPU_INT16S inc_a;
#if (AUDIO_CFG_SSM2377_EN == 0u)
CPU_INT16U init_b;
CPU_INT16U old_b;
CPU_INT16S inc_b;
#endif
CPU_BOOLEAN loop;
DTC_Dis();
while (DTC.DTCSTS.BIT.ACT != 0u);
old_per = MTU9.TGRA + 1u;
#if (AUDIO_CFG_SSM2377_EN > 0u)
old_a = MTU6.TGRA;
#else
old_a = MTU8.TGRA;
old_b = MTU8.TGRB;
#endif
/* Maintain duty cycle from old period. */
init_a = old_a * pwm_per / old_per;
#if (AUDIO_CFG_SSM2377_EN == 0u)
init_b = old_b * pwm_per / old_per;
#endif
/* ------------ SLOW RAMP TO 50% DUTY CYCLE ----------- */
MTUB.TITCR.BIT.T3ACOR = 8u - 1u; /* Signal at every 8 interrupts. */
MTUB.TITCR.BIT.T3AEN = 1u;
MTU9.TIER.BIT.TGIEA = 1u; /* Enable interrupt. */
half = pwm_per / 2u;
inc_a = (half > init_a) ? 1 : -1;
#if (AUDIO_CFG_SSM2377_EN == 0u)
inc_b = (half > init_b) ? 1 : -1;
#endif
IR(MTU9,TGIA9) = 0u;
while (IR(MTU9,TGIA9) == 0u);
#if (AUDIO_CFG_SSM2377_EN > 0u)
MTU6.TGRA = init_a;
#else
MTU8.TGRA = init_a;
MTU8.TGRB = init_b;
#endif
MTU9.TGRA = pwm_per - 1u;
do {
loop = DEF_FALSE;
IR(MTU9,TGIA9) = 0u;
while (IR(MTU9,TGIA9) == 0u);
if (DEF_ABS(half - init_a) >= DEF_ABS(inc_a)) {
init_a += inc_a;
#if (AUDIO_CFG_SSM2377_EN > 0u)
MTU6.TGRA = init_a;
#else
MTU8.TGRA = init_a;
#endif
loop = DEF_TRUE;
}
#if (AUDIO_CFG_SSM2377_EN == 0u)
if (DEF_ABS(half - init_b) >= DEF_ABS(inc_b)) {
init_b += inc_b;
MTU8.TGRB = init_b;
loop = DEF_TRUE;
}
#endif
} while (loop);
#if (AUDIO_CFG_SSM2377_EN > 0u)
MTU6.TGRA = half;
#else
MTU8.TGRA = half;
MTU8.TGRB = half;
#endif
MTU9.TIER.BIT.TGIEA = 0u; /* Disable interrupt. */
if (skip_cnt > 0u) { /* Cfg skip interrupts. */
MTUB.TITCR.BIT.T3ACOR = skip_cnt - 1u; /* Signals at every 'skip_cnt' interrupts */
MTUB.TITCR.BIT.T3AEN = 1u;
} else {
MTUB.TITCR.BIT.T3AEN = 0u;
}
}
/*
*********************************************************************************************************
* DTC_Init()
*
* Description : Initialize Data Transfer Controller (DTC).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void DTC_Init (void)
{
CPU_INT16U i;
DTC_VectorNull.Reserved = 0u;
DTC_VectorNull.MRA = 0u;
DTC_VectorNull.MRB = 0u;
DTC_VectorNull.SAR = 0u;
DTC_VectorNull.DAR = 0u;
DTC_VectorNull.CRA = 0u;
DTC_VectorNull.CRB = 0u;
DTC_VectorChA.Reserved = 0u;
#if (AUDIO_CFG_SSM2377_EN > 0u)
DTC_VectorChA.MRA = 0x18u; /* SAR Address Incremented; Word Transfer. */
DTC_VectorChA.MRB = 0u;
DTC_VectorChA.SAR = (void *)0u;
DTC_VectorChA.DAR = &MTU6.TGRA;
#else
DTC_VectorChA.MRA = 0x18u; /* SAR Address Incremented; Word Transfer. */
DTC_VectorChA.MRB = 0x80u; /* Chain Tranfer Enabled. */
DTC_VectorChA.SAR = (void *)0u;
DTC_VectorChA.DAR = &MTU8.TGRA;
#endif
DTC_VectorChA.CRA = 0u;
DTC_VectorChA.CRB = 0u;
DTC_VectorChB.Reserved = 0u;
#if (AUDIO_CFG_SSM2377_EN > 0u)
DTC_VectorChB.MRA = 0u;
DTC_VectorChB.MRB = 0u;
DTC_VectorChB.SAR = 0u;
DTC_VectorChB.DAR = 0u;
#else
DTC_VectorChB.MRA = 0x18u; /* SAR Address Incremented; Word Transfer. */
DTC_VectorChB.MRB = 0u;
DTC_VectorChB.SAR = (void *)0u;
DTC_VectorChB.DAR = &MTU8.TGRB;
#endif
DTC_VectorChB.CRA = 0u;
DTC_VectorChB.CRB = 0u;
DTC.DTCVBR = DTC_VectorTbl; /* Set DTC vector base register. */
for (i = 0u; i < 256u; i++) {
DTC_VectorTbl[i] = &DTC_VectorNull;
}
DTC_VectorTbl[157] = &DTC_VectorChA; /* MTU9 TGIA9 DTC Source. */
DTC.DTCCR.BIT.RRS = 1u; /* Skip transfer data read when vector numbers match. */
}
/*
*********************************************************************************************************
* DTC_En()
*
* Description : Enable Data Transfer Controller (DTC).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void DTC_En (void)
{
DTC.DTCST.BIT.DTCST = 1u;
MTU9.TIER.BIT.TGIEA = 1u; /* Enable interrupt on TGRA. */
IPR (MTU9, TGIA9) = 12u;
DTC_IntAck();
IEN (MTU9, TGIA9) = 1u;
}
/*
*********************************************************************************************************
* DTC_Dis()
*
* Description : Disable Data Transfer Controller (DTC).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void DTC_Dis (void)
{
DTC.DTCST.BIT.DTCST = 0u;
MTU9.TIER.BIT.TGIEA = 0u;
IPR (MTU9, TGIA9) = 0u;
DTCE(MTU9, TGIA9) = 0u;
IR (MTU9, TGIA9) = 0u;
IEN (MTU9, TGIA9) = 0u;
}
/*
*********************************************************************************************************
* DTC_IntAck()
*
* Description : Acknowledge interrupt on Data Transfer Controller (DTC).
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void DTC_IntAck (void)
{
DTCE(MTU9, TGIA9) = 1u;
IR (MTU9, TGIA9) = 0u;
}
/*
*********************************************************************************************************
* DTC_SetXfer()
*
* Description : Set data transfer on Data Transfer Controller (DTC).
*
* Argument(s) : p_buf Pointer to audio buffer to transfer.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void DTC_SetXfer(AUDIO_BUF *p_buf)
{
#if (AUDIO_CFG_SSM2377_EN == 0u)
void *p_data_right;
#endif
CPU_SIZE_T size;
if (p_buf == (AUDIO_BUF *)0) {
return;
}
switch (AudioStream_Channels) {
case 1u:
#if (AUDIO_CFG_SSM2377_EN == 0u)
p_data_right = p_buf->DataPtr;
#endif
size = p_buf->Samples;
break;
case 2u:
#if (AUDIO_CFG_SSM2377_EN == 0u)
p_data_right = (CPU_INT08U *)p_buf->DataPtr + (AUDIO_CFG_BUF_SIZE / 2u);
#endif
size = p_buf->Samples / 2u;
break;
default:
return;
}
DTC_VectorChA.SAR = p_buf->DataPtr;
DTC_VectorChA.CRA = size;
#if (AUDIO_CFG_SSM2377_EN == 0u)
DTC_VectorChB.SAR = p_data_right;
DTC_VectorChB.CRA = size;
#endif
}
/*
*********************************************************************************************************
* AudioCallbackHandler()
*
* Description : Audio transfer complete callback handler.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void AudioCallbackHandler (void)
{
AUDIO_BUF *p_buf;
AUDIO_BUF *p_buf_next;
OS_ERR os_err;
if (AudioBuf_Q.Entries > 0u) {
p_buf = AudioBuf_Q.HeadPtr; /* Get the first element of the queue. */
if (AudioBuf_Q.Entries > 1u) {
p_buf_next = p_buf->NextPtr;
/* ... Start DMA transfer. */
DTC_SetXfer(p_buf_next);
DTC_IntAck();
AudioBuf_Q.HeadPtr = p_buf_next;
} else {
AudioBuf_Q.HeadPtr = (AUDIO_BUF *)0;
AudioBuf_Q.TailPtr = (AUDIO_BUF *)0;
AudioStream_Buffering = DEF_TRUE;
if (AudioStream_State == AUDIO_STREAM_CLOSING) {
AudioStream_State = AUDIO_STREAM_CLOSED;
OSSemPost(&AudioStream_ClosedSem, /* Post to stream closed semaphore. */
OS_OPT_POST_1,
&os_err);
}
DTC_Dis();
}
AudioBuf_Q.Entries--;
AudioBuf_Abort(p_buf); /* Return buffer header + data to the memory pools. */
}
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex5/Webpages/webpages.h
|
/*
*********************************************************************************************************
* uC/HTTPs
* Hypertext Transfer Protocol (server)
*
* (c) Copyright 2003-2009; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/HTTPs is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/HTTPs in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/HTTPs. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NO FILE SYSTEM
*
* Filename : webpages.h
* Version : V1.00
* Programmer(s) : AA
*********************************************************************************************************
* Note(s) : (1) This file defines the various arrays' content being used as file.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DEFINES
*********************************************************************************************************
*/
/* File names */
#define STATIC_INDEX_HTML_NAME "\\index.html"
#define STATIC_LOGO_GIF_NAME "\\logo.gif"
/* Size of files in bytes on file system */
#define STATIC_INDEX_HTML_LEN 3009
#define STATIC_LOGO_GIF_LEN 2066
/*
*********************************************************************************************************
* FILES IN FILE SYSTEM
*********************************************************************************************************
*/
/* index.html file */
const unsigned char Index_html[]=
{
0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x50,
0x55, 0x42, 0x4c, 0x49, 0x43, 0x20, 0x22, 0x2d, 0x2f, 0x2f, 0x57, 0x33, 0x43, 0x2f, 0x2f, 0x44,
0x54, 0x44, 0x20, 0x48, 0x54, 0x4d, 0x4c, 0x20, 0x34, 0x2e, 0x30, 0x31, 0x2f, 0x2f, 0x45, 0x4e,
0x22, 0x0d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x22, 0x68, 0x74, 0x74, 0x70,
0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x77, 0x33, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x54, 0x52,
0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x34, 0x2f, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74, 0x2e, 0x64, 0x74,
0x64, 0x22, 0x3e, 0x0d, 0x0a, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d, 0x0a, 0x3c, 0x68, 0x65,
0x61, 0x64, 0x3e, 0x0d, 0x0a, 0x09, 0x3c, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x3e, 0x26, 0x6d, 0x69,
0x63, 0x72, 0x6f, 0x3b, 0x43, 0x2f, 0x48, 0x54, 0x54, 0x50, 0x73, 0x3c, 0x2f, 0x74, 0x69, 0x74,
0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x09, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x20, 0x6e, 0x61, 0x6d, 0x65,
0x3d, 0x22, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x22, 0x20, 0x63, 0x6f, 0x6e,
0x74, 0x65, 0x6e, 0x74, 0x3d, 0x22, 0x42, 0x42, 0x45, 0x64, 0x69, 0x74, 0x20, 0x39, 0x2e, 0x33,
0x22, 0x3e, 0x0d, 0x0a, 0x09, 0x3c, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x20, 0x74, 0x79, 0x70, 0x65,
0x3d, 0x22, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x63, 0x73, 0x73, 0x22, 0x20, 0x74, 0x69, 0x74, 0x6c,
0x65, 0x3d, 0x22, 0x74, 0x65, 0x78, 0x74, 0x2f, 0x63, 0x73, 0x73, 0x22, 0x3e, 0x0d, 0x0a, 0x0d,
0x0a, 0x09, 0x09, 0x68, 0x74, 0x6d, 0x6c, 0x20, 0x7b, 0x20, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74,
0x3a, 0x31, 0x30, 0x30, 0x25, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x62, 0x6f, 0x64, 0x79,
0x20, 0x7b, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x3b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x30, 0x61,
0x30, 0x61, 0x30, 0x61, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x66, 0x61, 0x6d, 0x69, 0x6c,
0x79, 0x3a, 0x41, 0x72, 0x69, 0x61, 0x6c, 0x2c, 0x20, 0x73, 0x61, 0x6e, 0x73, 0x2d, 0x73, 0x65,
0x72, 0x69, 0x66, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x3a, 0x31,
0x34, 0x70, 0x78, 0x3b, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x2d, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74,
0x3a, 0x32, 0x31, 0x70, 0x78, 0x3b, 0x20, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3a, 0x31, 0x30,
0x30, 0x25, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x2a, 0x20, 0x7b, 0x20, 0x66, 0x6f, 0x6e,
0x74, 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x3a, 0x31, 0x65, 0x6d, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67,
0x69, 0x6e, 0x3a, 0x30, 0x3b, 0x20, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x30, 0x3b,
0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x75, 0x6c, 0x2c, 0x20, 0x6f, 0x6c, 0x20, 0x7b, 0x20, 0x70,
0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x2d, 0x6c, 0x65, 0x66, 0x74, 0x3a, 0x31, 0x2e, 0x36, 0x65,
0x6d, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x7b,
0x20, 0x6d, 0x69, 0x6e, 0x2d, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x20, 0x31, 0x2e, 0x35, 0x65,
0x6d, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x0d, 0x0a, 0x09, 0x09, 0x69, 0x6e, 0x70, 0x75,
0x74, 0x20, 0x7b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x73, 0x69, 0x7a, 0x65, 0x3a, 0x31, 0x30,
0x70, 0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x2e, 0x62,
0x6c, 0x75, 0x65, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x20, 0x7b, 0x62, 0x61, 0x63, 0x6b, 0x67,
0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x64, 0x64, 0x65, 0x32, 0x65, 0x36, 0x3b, 0x20, 0x62,
0x6f, 0x72, 0x64, 0x65, 0x72, 0x3a, 0x32, 0x70, 0x78, 0x20, 0x73, 0x6f, 0x6c, 0x69, 0x64, 0x20,
0x23, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23,
0x32, 0x32, 0x33, 0x64, 0x35, 0x30, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x77, 0x65, 0x69,
0x67, 0x68, 0x74, 0x3a, 0x62, 0x6f, 0x6c, 0x64, 0x3b, 0x20, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e,
0x67, 0x3a, 0x33, 0x70, 0x78, 0x20, 0x35, 0x70, 0x78, 0x20, 0x33, 0x70, 0x78, 0x20, 0x35, 0x70,
0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2c,
0x20, 0x74, 0x64, 0x20, 0x7b, 0x20, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x3a, 0x6e, 0x6f, 0x6e,
0x65, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x30, 0x3b, 0x20, 0x70, 0x61, 0x64,
0x64, 0x69, 0x6e, 0x67, 0x3a, 0x30, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x23,
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x73, 0x20, 0x7b, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74,
0x3a, 0x72, 0x69, 0x67, 0x68, 0x74, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x30,
0x20, 0x33, 0x30, 0x70, 0x78, 0x20, 0x30, 0x20, 0x30, 0x3b, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68,
0x3a, 0x33, 0x37, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x23,
0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x7b, 0x20, 0x63, 0x6c, 0x65, 0x61,
0x72, 0x3a, 0x62, 0x6f, 0x74, 0x68, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x2d, 0x73, 0x69, 0x7a,
0x65, 0x3a, 0x31, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a,
0x33, 0x30, 0x70, 0x78, 0x20, 0x30, 0x20, 0x30, 0x20, 0x30, 0x3b, 0x20, 0x74, 0x65, 0x78, 0x74,
0x2d, 0x61, 0x6c, 0x69, 0x67, 0x6e, 0x3a, 0x72, 0x69, 0x67, 0x68, 0x74, 0x3b, 0x20, 0x7d, 0x0d,
0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x20, 0x7b, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x3a, 0x6c, 0x65, 0x66, 0x74, 0x3b, 0x20,
0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x30, 0x20, 0x33, 0x30, 0x70, 0x78, 0x20, 0x30, 0x20,
0x30, 0x3b, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x33, 0x37, 0x30, 0x70, 0x78, 0x3b, 0x20,
0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x20, 0x61, 0x3a, 0x6c, 0x69, 0x6e, 0x6b, 0x20, 0x7b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72,
0x3a, 0x23, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23,
0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x3a, 0x76, 0x69,
0x73, 0x69, 0x74, 0x65, 0x64, 0x20, 0x7b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x63,
0x63, 0x63, 0x63, 0x63, 0x63, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x69, 0x6e, 0x66,
0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x61, 0x3a, 0x68, 0x6f, 0x76, 0x65, 0x72,
0x20, 0x7b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x66, 0x61, 0x39, 0x35, 0x30, 0x30,
0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x20, 0x61, 0x3a, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0x20, 0x7b, 0x20, 0x63,
0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x66, 0x61, 0x39, 0x35, 0x30, 0x30, 0x3b, 0x20, 0x7d, 0x0d,
0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x70, 0x61, 0x67, 0x65, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x7b,
0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x32, 0x32, 0x33,
0x64, 0x35, 0x30, 0x3b, 0x20, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x30, 0x20, 0x30,
0x20, 0x33, 0x30, 0x70, 0x78, 0x20, 0x30, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x70,
0x61, 0x67, 0x65, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x68, 0x32, 0x20, 0x7b, 0x20, 0x63, 0x6f, 0x6c,
0x6f, 0x72, 0x3a, 0x23, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74,
0x2d, 0x73, 0x69, 0x7a, 0x65, 0x3a, 0x31, 0x38, 0x70, 0x78, 0x3b, 0x20, 0x66, 0x6f, 0x6e, 0x74,
0x2d, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3a, 0x62, 0x6f, 0x6c, 0x64, 0x3b, 0x20, 0x6d, 0x61,
0x72, 0x67, 0x69, 0x6e, 0x3a, 0x33, 0x30, 0x70, 0x78, 0x20, 0x30, 0x20, 0x31, 0x34, 0x70, 0x78,
0x20, 0x33, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x70, 0x61, 0x67,
0x65, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x70, 0x20, 0x7b, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a,
0x23, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a,
0x30, 0x20, 0x33, 0x30, 0x70, 0x78, 0x20, 0x31, 0x34, 0x70, 0x78, 0x20, 0x33, 0x30, 0x70, 0x78,
0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x70, 0x61, 0x67, 0x65, 0x62, 0x6f, 0x64, 0x79,
0x20, 0x70, 0x2e, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x62, 0x6f, 0x78, 0x20, 0x7b, 0x20, 0x62, 0x61,
0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x66, 0x61, 0x39, 0x35, 0x30, 0x30,
0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x33, 0x30, 0x70, 0x78, 0x20, 0x32, 0x30,
0x70, 0x78, 0x20, 0x31, 0x34, 0x70, 0x78, 0x20, 0x32, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x70, 0x61,
0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x35, 0x70, 0x78, 0x20, 0x31, 0x30, 0x70, 0x78, 0x20, 0x35,
0x70, 0x78, 0x20, 0x31, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09,
0x23, 0x70, 0x61, 0x67, 0x65, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x20, 0x7b, 0x20, 0x62,
0x61, 0x63, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x3b, 0x20, 0x6d, 0x61, 0x72, 0x67, 0x69, 0x6e, 0x3a, 0x30, 0x20, 0x61, 0x75, 0x74, 0x6f,
0x20, 0x30, 0x20, 0x61, 0x75, 0x74, 0x6f, 0x3b, 0x20, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3a, 0x38,
0x30, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x23, 0x74, 0x6f,
0x70, 0x62, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x20, 0x7b, 0x20, 0x62, 0x61, 0x63, 0x6b, 0x67, 0x72,
0x6f, 0x75, 0x6e, 0x64, 0x3a, 0x23, 0x64, 0x64, 0x65, 0x32, 0x65, 0x36, 0x3b, 0x20, 0x70, 0x61,
0x64, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x32, 0x30, 0x70, 0x78, 0x3b, 0x20, 0x7d, 0x0d, 0x0a, 0x09,
0x09, 0x23, 0x74, 0x6f, 0x70, 0x62, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x20, 0x70, 0x20, 0x7b, 0x20,
0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x3a, 0x23, 0x32, 0x32, 0x33, 0x64, 0x35, 0x30, 0x3b, 0x20, 0x7d,
0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x3c, 0x2f, 0x73, 0x74, 0x79, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x3c,
0x2f, 0x68, 0x65, 0x61, 0x64, 0x3e, 0x0d, 0x0a, 0x3c, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0d, 0x0a,
0x0d, 0x0a, 0x3c, 0x64, 0x69, 0x76, 0x20, 0x69, 0x64, 0x3d, 0x22, 0x70, 0x61, 0x67, 0x65, 0x77,
0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x22, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x3c, 0x64, 0x69,
0x76, 0x20, 0x69, 0x64, 0x3d, 0x22, 0x74, 0x6f, 0x70, 0x62, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x22,
0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x3c, 0x69, 0x6d, 0x67, 0x20, 0x73, 0x72, 0x63, 0x3d, 0x22, 0x6c,
0x6f, 0x67, 0x6f, 0x2e, 0x67, 0x69, 0x66, 0x22, 0x20, 0x61, 0x6c, 0x74, 0x3d, 0x22, 0x22, 0x20,
0x77, 0x69, 0x64, 0x74, 0x68, 0x3d, 0x22, 0x32, 0x31, 0x32, 0x22, 0x20, 0x68, 0x65, 0x69, 0x67,
0x68, 0x74, 0x3d, 0x22, 0x34, 0x31, 0x22, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x3c,
0x73, 0x74, 0x72, 0x6f, 0x6e, 0x67, 0x3e, 0x41, 0x20, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x20,
0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x26, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x3b, 0x43, 0x2f,
0x54, 0x43, 0x50, 0x2d, 0x49, 0x50, 0x20, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x20, 0x46,
0x61, 0x6d, 0x69, 0x6c, 0x79, 0x3c, 0x2f, 0x73, 0x74, 0x72, 0x6f, 0x6e, 0x67, 0x3e, 0x3c, 0x2f,
0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x0d, 0x0a, 0x09, 0x0d, 0x0a,
0x09, 0x3c, 0x64, 0x69, 0x76, 0x20, 0x69, 0x64, 0x3d, 0x22, 0x70, 0x61, 0x67, 0x65, 0x62, 0x6f,
0x64, 0x79, 0x22, 0x3e, 0x0d, 0x0a, 0x09, 0x0d, 0x0a, 0x09, 0x09, 0x3c, 0x64, 0x69, 0x76, 0x20,
0x69, 0x64, 0x3d, 0x22, 0x69, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22,
0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x3c, 0x70, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x22,
0x61, 0x6c, 0x65, 0x72, 0x74, 0x62, 0x6f, 0x78, 0x22, 0x3e, 0x59, 0x6f, 0x75, 0x72, 0x20, 0x48,
0x54, 0x54, 0x50, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, 0x69, 0x73, 0x20, 0x77, 0x6f,
0x72, 0x6b, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x72, 0x6f, 0x70, 0x65, 0x72, 0x6c, 0x79, 0x2e, 0x3c,
0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x3c, 0x61, 0x20, 0x68, 0x72,
0x65, 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x6d,
0x69, 0x63, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75,
0x63, 0x74, 0x73, 0x2f, 0x72, 0x74, 0x6f, 0x73, 0x2f, 0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x2f,
0x72, 0x74, 0x6f, 0x73, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x26, 0x6d, 0x69, 0x63, 0x72,
0x6f, 0x3b, 0x43, 0x2f, 0x4f, 0x53, 0x2d, 0x49, 0x49, 0x49, 0x3c, 0x2f, 0x61, 0x3e, 0x20, 0x56,
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x24, 0x7b, 0x4f, 0x53, 0x5f, 0x56, 0x45, 0x52,
0x53, 0x49, 0x4f, 0x4e, 0x7d, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x3c, 0x70,
0x3e, 0x3c, 0x61, 0x20, 0x68, 0x72, 0x65, 0x66, 0x3d, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f,
0x2f, 0x77, 0x77, 0x77, 0x2e, 0x6d, 0x69, 0x63, 0x72, 0x69, 0x75, 0x6d, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x74, 0x63, 0x70, 0x2d, 0x69, 0x70,
0x2f, 0x74, 0x63, 0x70, 0x2d, 0x69, 0x70, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x3e, 0x26, 0x6d,
0x69, 0x63, 0x72, 0x6f, 0x3b, 0x43, 0x2f, 0x54, 0x43, 0x50, 0x2d, 0x49, 0x50, 0x3c, 0x2f, 0x61,
0x3e, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x24, 0x7b, 0x4e, 0x45, 0x54,
0x5f, 0x56, 0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x7d, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09,
0x09, 0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x3c, 0x64, 0x69,
0x76, 0x20, 0x69, 0x64, 0x3d, 0x22, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x73, 0x22, 0x3e,
0x0d, 0x0a, 0x09, 0x09, 0x09, 0x3c, 0x68, 0x32, 0x3e, 0x45, 0x76, 0x61, 0x6c, 0x20, 0x42, 0x6f,
0x61, 0x72, 0x64, 0x20, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d,
0x0a, 0x09, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x54, 0x65, 0x6d, 0x70, 0x65, 0x72, 0x61, 0x74, 0x75,
0x72, 0x65, 0x20, 0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x3a, 0x20, 0x24, 0x7b, 0x54, 0x45, 0x4d,
0x50, 0x5f, 0x43, 0x7d, 0x26, 0x64, 0x65, 0x67, 0x3b, 0x43, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a,
0x09, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x54, 0x65, 0x6d, 0x70, 0x65, 0x72, 0x61, 0x74, 0x75, 0x72,
0x65, 0x20, 0x73, 0x65, 0x6e, 0x73, 0x6f, 0x72, 0x3a, 0x20, 0x24, 0x7b, 0x54, 0x45, 0x4d, 0x50,
0x5f, 0x46, 0x7d, 0x26, 0x64, 0x65, 0x67, 0x3b, 0x46, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09,
0x09, 0x09, 0x3c, 0x68, 0x32, 0x3e, 0x45, 0x76, 0x61, 0x6c, 0x20, 0x42, 0x6f, 0x61, 0x72, 0x64,
0x20, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x73, 0x3c, 0x2f, 0x68, 0x32, 0x3e, 0x0d, 0x0a,
0x09, 0x09, 0x09, 0x3c, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09,
0x3c, 0x74, 0x72, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x74, 0x64, 0x3e, 0x0d,
0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x61, 0x63, 0x74,
0x69, 0x6f, 0x6e, 0x3d, 0x22, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0x22,
0x20, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3d, 0x22, 0x50, 0x4f, 0x53, 0x54, 0x22, 0x3e, 0x20,
0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09,
0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x6e, 0x61, 0x6d,
0x65, 0x3d, 0x22, 0x4c, 0x45, 0x44, 0x22, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x68, 0x69,
0x64, 0x64, 0x65, 0x6e, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x4c, 0x45, 0x44,
0x31, 0x22, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x69, 0x6e,
0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74,
0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x54, 0x6f, 0x67, 0x67, 0x6c, 0x65, 0x20,
0x4c, 0x45, 0x44, 0x20, 0x31, 0x35, 0x22, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x22, 0x62,
0x6c, 0x75, 0x65, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x22, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09,
0x09, 0x09, 0x09, 0x09, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
0x3c, 0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x2f,
0x74, 0x64, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x74, 0x64, 0x3e, 0x0d, 0x0a,
0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x61, 0x63, 0x74, 0x69,
0x6f, 0x6e, 0x3d, 0x22, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0x22, 0x20,
0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x3d, 0x22, 0x50, 0x4f, 0x53, 0x54, 0x22, 0x3e, 0x20, 0x0d,
0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09,
0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x69, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x6e, 0x61, 0x6d, 0x65,
0x3d, 0x22, 0x4c, 0x45, 0x44, 0x22, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x68, 0x69, 0x64,
0x64, 0x65, 0x6e, 0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x4c, 0x45, 0x44, 0x32,
0x22, 0x3e, 0x20, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x69, 0x6e,
0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3d, 0x22, 0x73, 0x75, 0x62, 0x6d, 0x69, 0x74,
0x22, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x22, 0x54, 0x6f, 0x67, 0x67, 0x6c, 0x65, 0x20,
0x4c, 0x45, 0x44, 0x20, 0x34, 0x22, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x3d, 0x22, 0x62, 0x6c,
0x75, 0x65, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x22, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09,
0x09, 0x09, 0x09, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c,
0x2f, 0x66, 0x6f, 0x72, 0x6d, 0x3e, 0x20, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x2f,
0x74, 0x64, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x09, 0x09, 0x3c, 0x2f, 0x74, 0x72, 0x3e, 0x0d, 0x0a,
0x09, 0x09, 0x09, 0x3c, 0x2f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x3e, 0x0d, 0x0a, 0x09, 0x09, 0x3c,
0x2f, 0x64, 0x69, 0x76, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x09, 0x3c, 0x64, 0x69, 0x76, 0x20,
0x69, 0x64, 0x3d, 0x22, 0x63, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74, 0x22, 0x3e, 0x0d,
0x0a, 0x09, 0x09, 0x09, 0x3c, 0x70, 0x3e, 0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68, 0x74,
0x20, 0x32, 0x30, 0x31, 0x30, 0x20, 0x4d, 0x69, 0x63, 0x72, 0x69, 0x26, 0x6d, 0x69, 0x63, 0x72,
0x6f, 0x3b, 0x6d, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x3c, 0x2f, 0x70, 0x3e, 0x0d, 0x0a, 0x09, 0x09,
0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x09, 0x3c, 0x2f, 0x64, 0x69, 0x76,
0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c, 0x2f, 0x64, 0x69, 0x76, 0x3e, 0x0d, 0x0a, 0x0d, 0x0a, 0x3c,
0x2f, 0x62, 0x6f, 0x64, 0x79, 0x3e, 0x0d, 0x0a, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x0d,
0x0a } ;
/* logo.gif file */
const unsigned char Logo_Gif[]=
{ \
0x47,0x49,0x46,0x38,0x39,0x61,0xd4,0x00,0x29,0x00,0xc4,0x00,0x00, \
0x29,0x49,0x5b,0x77,0x8b,0x97,0x35,0x53,0x64,0xcd,0xd5,0xd9,0xa4, \
0xb1,0xb9,0x63,0x7a,0x88,0xae,0xba,0xc1,0xc3,0xcc,0xd2,0x9b,0xaa, \
0xb3,0xd0,0xd7,0xdc,0xbb,0xc5,0xcb,0x95,0xa5,0xae,0x49,0x64,0x74, \
0x8a,0x9b,0xa6,0xd6,0xdc,0xe0,0x84,0x96,0xa1,0x52,0x6c,0x7b,0x1f, \
0x40,0x53,0xc9,0xd1,0xd7,0x40,0x5c,0x6c,0x7b,0x8e,0x9a,0xbe,0xc8, \
0xce,0xb7,0xc2,0xc8,0x71,0x86,0x92,0x8e,0x9f,0xa9,0x87,0x99,0xa3, \
0x69,0x7f,0x8c,0x59,0x71,0x80,0x7f,0x92,0x9e,0xb4,0xbf,0xc6,0x18, \
0x3a,0x4e,0xff,0xff,0xff,0x21,0xf9,0x04,0x01,0x00,0x00,0x1f,0x00, \
0x2c,0x00,0x00,0x00,0x00,0xd4,0x00,0x29,0x00,0x00,0x05,0xff,0xe0, \
0x27,0x8e,0x64,0x69,0x9e,0x68,0x3a,0x10,0xc1,0xc6,0x4c,0x13,0x54, \
0x34,0x4a,0x3a,0x62,0xc2,0xb4,0x39,0x63,0x82,0x65,0x8d,0x60,0x23, \
0x53,0x31,0x39,0x16,0x40,0xe1,0xc3,0x22,0x32,0x3c,0x84,0xd0,0xa8, \
0xb4,0xf1,0xe8,0x7c,0x7e,0xd3,0x2c,0x14,0x93,0x10,0x21,0x92,0xda, \
0x85,0x41,0x62,0x2b,0x1b,0x1d,0xe8,0xb4,0x1a,0xfd,0x51,0x9b,0xdf, \
0x70,0xd2,0x20,0x00,0xf0,0xd8,0xef,0x78,0x88,0x35,0x05,0xb1,0x6f, \
0x48,0x12,0x75,0x78,0x1e,0x08,0x46,0x02,0x83,0x1e,0x0f,0x22,0x17, \
0x88,0x8d,0x8e,0x14,0x1f,0x82,0x8e,0x93,0x1e,0x11,0x07,0x22,0x0c, \
0x94,0x78,0x00,0x05,0x45,0x71,0x29,0x08,0x00,0x02,0xa3,0xa3,0x13, \
0x07,0x10,0x02,0x00,0x0b,0x1f,0x04,0xa5,0x9f,0xaf,0x29,0x06,0x87, \
0x9a,0x95,0x0d,0x28,0x09,0xb3,0x19,0x80,0x92,0x77,0x85,0x25,0x0e, \
0xb3,0x78,0x8a,0x1f,0x01,0xb4,0x93,0x90,0xbc,0xc6,0x77,0x96,0x98, \
0xca,0x76,0x00,0x06,0xb0,0x26,0x18,0x88,0x00,0x15,0xb3,0x7f,0x8c, \
0x1e,0x00,0xd2,0xdd,0x22,0x04,0x11,0xce,0x1e,0x18,0x27,0x06,0x77, \
0xd1,0x23,0x81,0x88,0xbe,0x24,0xc0,0x88,0xc3,0xc5,0xe2,0x78,0xc8, \
0xf2,0xcb,0x97,0x1f,0x99,0xe2,0x00,0xf7,0xde,0x03,0x0a,0x1d,0x75, \
0x0a,0x1c,0xa8,0x80,0x6b,0x9b,0x80,0x04,0x13,0x22,0x28,0xf4,0x26, \
0xad,0x42,0x32,0x5a,0x11,0x98,0x94,0x78,0x60,0xe7,0xe0,0xae,0x75, \
0x86,0xde,0x89,0x88,0x57,0xcf,0x03,0xbd,0x8e,0xcc,0xf0,0xd5,0x0b, \
0xc0,0xb0,0xc7,0xa1,0x0b,0x22,0x80,0xff,0x45,0xd8,0xe0,0x61,0x41, \
0x04,0x06,0x02,0x22,0x94,0x7c,0xc5,0xb2,0xd1,0x84,0x02,0x1b,0x82, \
0xe1,0xf9,0x53,0xa2,0x26,0x84,0x12,0xea,0x06,0xb1,0x1b,0xe1,0x6e, \
0xd0,0x30,0x6d,0x1d,0x3f,0xd6,0x0b,0x99,0x0f,0x0f,0x83,0x21,0x14, \
0xfa,0x20,0x9a,0x30,0xf3,0x43,0x41,0x94,0x6d,0x62,0x36,0xf0,0x30, \
0xc1,0x03,0x87,0x98,0xaf,0x12,0x48,0x18,0x4b,0x96,0x47,0x4a,0xb2, \
0x64,0xbb,0x88,0xe8,0x10,0x6e,0x10,0x00,0x76,0x09,0x38,0xe2,0x41, \
0x27,0xa2,0x60,0x22,0xa0,0x0f,0x87,0xa6,0xd4,0x69,0x67,0x98,0x93, \
0x0c,0x80,0x81,0xc8,0xbd,0x73,0x61,0x48,0xe0,0x2a,0x57,0x02,0x03, \
0xc6,0xd0,0xf4,0xce,0x84,0x1f,0x8a,0x1b,0xa8,0x6d,0x6c,0x07,0xeb, \
0xc6,0x6a,0x64,0x4a,0x1c,0x30,0x80,0x00,0x83,0x67,0x04,0x06,0x06, \
0xa4,0xb8,0xba,0xd7,0x83,0x81,0x3a,0x11,0x08,0x00,0x90,0xf9,0xe9, \
0x41,0x04,0x00,0xb0,0x45,0xf1,0x3b,0x10,0x1b,0x76,0x84,0x61,0xc4, \
0x1a,0x11,0x30,0xa1,0x61,0x13,0x83,0xdd,0x23,0x3a,0x9c,0xc3,0x8b, \
0xf1,0x17,0xdf,0xbb,0x28,0x2c,0x34,0x92,0xf8,0xa6,0xf7,0x20,0x9e, \
0x28,0x28,0x7b,0xb0,0xfc,0xe1,0x40,0xdb,0x65,0x9e,0xbe,0x31,0xb8, \
0xbe,0xa9,0xd3,0x09,0xd2,0x56,0x0f,0x9d,0xe2,0x1a,0x88,0x75,0x1c, \
0x0a,0x83,0x22,0x64,0xb7,0x3e,0x08,0x52,0xb3,0x41,0x3f,0x4d,0x28, \
0xb8,0x89,0xa1,0x83,0x5a,0x12,0x19,0x9e,0x89,0xbe,0x38,0x88,0x43, \
0x07,0x03,0x00,0x06,0x78,0x1c,0x6e,0x26,0x28,0x87,0xc8,0x1e,0x6f, \
0x14,0x80,0x48,0xff,0x7c,0xd1,0x21,0x42,0x5d,0x05,0xdc,0x55,0xc2, \
0x0f,0x52,0x93,0x40,0x63,0x42,0x41,0x24,0xb5,0x91,0x90,0x04,0x14, \
0x69,0xe0,0x00,0x6c,0xaf,0xa0,0x87,0x87,0x7a,0x23,0xb0,0x37,0x4f, \
0x5d,0x0f,0xe9,0x72,0x86,0x0d,0x3e,0x99,0x10,0x54,0x47,0x04,0x96, \
0x60,0xe0,0x20,0x08,0x9a,0xa1,0x20,0x7c,0x36,0x48,0x47,0x9d,0x73, \
0x9b,0xa8,0xb5,0x95,0x31,0x02,0xec,0x47,0xd4,0x40,0xfb,0x39,0x70, \
0xc0,0x01,0x0e,0x24,0x50,0x81,0x68,0x47,0x86,0x98,0xde,0x7a,0x11, \
0xba,0x67,0x22,0x1e,0xc0,0x7d,0x52,0x14,0x07,0x2e,0x3e,0xe4,0x4c, \
0x8c,0x24,0xcc,0x88,0x47,0x8d,0x65,0xdc,0x98,0x47,0x8e,0x88,0x30, \
0xc0,0x01,0x05,0x17,0x74,0xb5,0x60,0x4a,0x6a,0xda,0x71,0xdb,0x3f, \
0x14,0xda,0xe1,0x5e,0x55,0x65,0x88,0x88,0x5d,0x89,0x51,0x8a,0x60, \
0x41,0x84,0x1e,0x80,0xf9,0xc6,0x8c,0x74,0xa5,0xa3,0xa5,0x32,0x5c, \
0x8e,0xe0,0xe5,0x1d,0x7e,0xa6,0x20,0xe6,0x1d,0x0c,0x9e,0x20,0x1d, \
0x2d,0xbe,0xbc,0xe8,0x81,0x00,0x66,0x7d,0x10,0x95,0x06,0x14,0x60, \
0x80,0x40,0xa2,0x74,0x96,0x60,0xa7,0x9b,0x50,0xb6,0xa7,0x67,0x23, \
0x9c,0xda,0x40,0xcd,0x36,0x42,0x0a,0xda,0x51,0x5f,0x29,0x1c,0x6a, \
0x47,0xa9,0x26,0x2c,0x6a,0x47,0xa3,0x26,0x3c,0x4a,0x09,0x74,0x92, \
0x7a,0x00,0x01,0x06,0x06,0x54,0x50,0x69,0xa7,0x40,0x35,0x40,0x01, \
0x98,0x9f,0x56,0x12,0xea,0x89,0x1f,0x40,0x88,0x48,0xa0,0x70,0xdc, \
0xc8,0xc0,0x09,0xb9,0x8a,0x53,0xe8,0xa8,0x07,0xc6,0x21,0xab,0xff, \
0xae,0x64,0x3a,0xb3,0xc1,0x7d,0x22,0x35,0xf2,0xda,0x04,0x1a,0x20, \
0xc0,0x2d,0x9d,0x07,0x04,0x33,0x54,0xb1,0x24,0x8a,0x30,0xa5,0x9c, \
0x22,0x44,0xab,0xd7,0x08,0x0f,0x2c,0x90,0x59,0x3b,0xb3,0xcc,0xc9, \
0x5f,0x1e,0x17,0xe4,0xab,0xef,0x05,0x0f,0x4d,0xfb,0x81,0xab,0x7d, \
0x5a,0xbb,0x66,0x0a,0xb6,0xba,0x05,0xc1,0xbb,0x04,0x00,0xf9,0xee, \
0x27,0x38,0x6d,0xe0,0xb0,0xc3,0x6d,0x72,0x55,0x29,0xba,0xd9,0x29, \
0x8b,0xac,0x03,0x11,0xdb,0x91,0x21,0x71,0x00,0x40,0x40,0x83,0x59, \
0x0a,0xb4,0x55,0xe5,0xbd,0xbd,0x64,0x64,0x54,0xab,0xa4,0x0a,0x8c, \
0x23,0xc1,0x88,0x6c,0x40,0xc0,0xcb,0x2f,0x77,0x30,0xef,0x34,0x7c, \
0x36,0xb2,0x30,0x1c,0x83,0xde,0x01,0x80,0x90,0xe8,0xd6,0xd0,0x04, \
0x22,0x73,0x5e,0x3b,0xc1,0xaf,0x22,0x50,0x34,0x48,0x86,0xa7,0x02, \
0x30,0xb3,0xaa,0x42,0x99,0x2c,0x0c,0xca,0xd5,0x36,0x3b,0x70,0x83, \
0x83,0x50,0xf7,0x46,0x05,0x01,0x4c,0x90,0xf3,0xa4,0xe3,0xc6,0x11, \
0x81,0x00,0x0a,0x28,0x60,0x81,0x05,0x07,0x18,0x3d,0x2b,0x09,0xc5, \
0xb6,0x04,0x2f,0xd0,0x23,0x20,0xd0,0x08,0x96,0x5d,0x3e,0x44,0xce, \
0x07,0xce,0xa2,0xe0,0xae,0xd3,0x77,0xf8,0x0b,0x30,0xac,0x25,0x5c, \
0x4b,0x6b,0x09,0x3a,0x76,0x93,0x80,0x01,0x0d,0x68,0xb0,0x1d,0x22, \
0x23,0x7f,0x12,0x01,0x55,0xed,0x5c,0x10,0x0e,0x03,0xfc,0x58,0x8a, \
0x88,0x00,0x04,0xac,0xf0,0xd0,0x9c,0x18,0x37,0xe2,0xb2,0x05,0x06, \
0x70,0xf0,0x90,0xd2,0x59,0x69,0x6c,0x77,0xff,0x5e,0x78,0xb3,0x9a, \
0x5c,0xca,0x52,0xaf,0x4c,0x35,0x1e,0x56,0xa7,0x90,0xa4,0x04,0x9c, \
0x23,0x30,0x94,0x02,0x7c,0xad,0x22,0xcd,0xe2,0x27,0x0c,0x44,0x74, \
0xda,0x6e,0x3e,0x42,0x82,0xdb,0xf5,0xb8,0x67,0x71,0xe2,0x4c,0xe3, \
0xf1,0x6e,0x51,0x4f,0x9f,0x1e,0x75,0x82,0x53,0x3b,0xea,0x20,0x1c, \
0xfc,0x72,0x37,0x72,0xc6,0xcc,0x7a,0xcd,0xf8,0x1b,0xbc,0x53,0x62, \
0xef,0x07,0x71,0xd2,0x32,0x81,0x5a,0x0b,0x3c,0x13,0x39,0xc9,0x76, \
0x1c,0x3f,0x20,0xd4,0x34,0xaa,0x3c,0x26,0xcb,0x55,0xc3,0x71,0xea, \
0x26,0x14,0x10,0xb0,0x80,0x54,0x77,0x58,0x74,0xfb,0xf5,0x66,0x64, \
0x7f,0xcc,0x2f,0x35,0x01,0x99,0x9d,0x73,0xcf,0x1a,0x5d,0x71,0xe8, \
0xa5,0x11,0xe5,0xa5,0x2f,0x75,0xeb,0x5b,0x1d,0x61,0xe0,0xe0,0x80, \
0x82,0x21,0xc2,0x76,0xf7,0x3b,0x8f,0x3c,0xb6,0xd7,0x06,0x0a,0xd4, \
0x6c,0x10,0x90,0x23,0x81,0x9a,0x5a,0x57,0xbc,0x92,0x19,0xa7,0x80, \
0x27,0xd8,0x9b,0xfa,0x18,0x95,0x2d,0xd6,0xc5,0x41,0x02,0x0e,0x74, \
0xd3,0xdc,0xba,0x81,0x3b,0x38,0x14,0x0b,0x00,0x8e,0xb3,0x03,0x4e, \
0x6a,0x03,0x80,0x69,0x55,0x20,0x4d,0x7c,0x02,0x00,0x03,0x10,0xf0, \
0xab,0x90,0x95,0x4f,0x05,0x5a,0xa3,0x21,0xf1,0x1a,0x48,0x43,0x00, \
0xac,0x50,0x3e,0x45,0x04,0x5b,0x1c,0xf8,0x45,0xc3,0x02,0xb0,0xa8, \
0x88,0x70,0x83,0x43,0x02,0x1a,0x90,0x90,0x46,0x08,0x40,0x03,0x3e, \
0xf3,0x46,0x0b,0xb1,0x97,0x9e,0x23,0x89,0x21,0x49,0x03,0x48,0x80, \
0x18,0x07,0x40,0xb4,0xff,0x5f,0x6c,0x06,0x01,0x0b,0x58,0x00,0x68, \
0x96,0xd6,0xae,0x34,0x2e,0x20,0x55,0xbf,0x10,0xa3,0x1c,0xc5,0x58, \
0x46,0xab,0xcc,0x31,0x01,0x64,0x74,0xdd,0x1d,0xe9,0x18,0x07,0x3c, \
0xce,0x31,0x8c,0x36,0xf0,0xa3,0x1c,0xf3,0xf8,0x0a,0x07,0x48,0xa0, \
0x03,0xf2,0x53,0x23,0x01,0x14,0xd0,0xb5,0x08,0xba,0xf0,0x49,0xc0, \
0x8a,0xa4,0x24,0x27,0x49,0xc9,0x4a,0x92,0x60,0x8b,0xf9,0x83,0xa4, \
0x25,0x37,0xc9,0xc9,0x4e,0x7a,0xd2,0x04,0x98,0xac,0x93,0x26,0x3f, \
0x49,0xca,0x52,0x9a,0xb2,0x24,0xa1,0xb4,0x01,0xc5,0x4e,0xc9,0xca, \
0x56,0xba,0x32,0x05,0xa9,0x4c,0xc1,0x2a,0x5f,0x49,0xcb,0x5a,0x9a, \
0x32,0x96,0xc9,0xc1,0x80,0x1b,0xd3,0xd8,0xc8,0x0f,0x0c,0x00,0x8e, \
0x28,0x60,0x43,0x1b,0xd6,0x40,0xcc,0x62,0x96,0xd1,0x01,0x80,0xb4, \
0xa5,0x32,0x23,0x89,0xcb,0x92,0xc8,0x62,0x01,0x75,0x1c,0xc1,0x35, \
0x7c,0x01,0x81,0x0b,0x00,0x24,0x07,0xa9,0x30,0x9c,0x28,0x52,0xc1, \
0x00,0x0b,0x4c,0x20,0x15,0x02,0x80,0x60,0xb2,0x32,0xa1,0x8a,0x65, \
0x9a,0xb3,0x2a,0xcd,0x64,0x88,0x70,0x3c,0xc0,0x80,0xea,0x8d,0x20, \
0x61,0xd1,0x18,0x40,0x04,0x02,0xd0,0x01,0x08,0x64,0x22,0x06,0x19, \
0x28,0x00,0x04,0xbe,0x06,0x81,0xf8,0xb1,0x73,0x03,0xb0,0x99,0xd7, \
0x3e,0x35,0xd0,0x15,0xbe,0x9d,0xf3,0xa0,0xb0,0xc4,0x5f,0xa7,0xd6, \
0x29,0xc3,0xf1,0x89,0x80,0x03,0x1e,0x20,0x83,0x72,0x6c,0x17,0x3e, \
0xe6,0x1c,0xc0,0x2b,0x22,0x40,0x0f,0x19,0xc2,0xb7,0x87,0x04,0x70, \
0xff,0x22,0x59,0xe1,0xfc,0x40,0x07,0x34,0xc0,0x81,0x2e,0x18,0x60, \
0x01,0x2c,0x20,0xc2,0x07,0x38,0xa4,0x00,0x07,0x14,0x2e,0x1a,0x3e, \
0xe8,0x00,0x05,0x98,0x83,0x50,0x56,0x7e,0x6d,0x97,0x38,0xcd,0xa9, \
0x4e,0x77,0x8a,0x80,0x17,0x96,0xb4,0x6f,0xb7,0xc1,0x40,0x6f,0xf6, \
0xe0,0x38,0x21,0x99,0x03,0x38,0x39,0x11,0x41,0x01,0x22,0x30,0xaf, \
0xae,0x34,0xc0,0x2c,0x06,0xf8,0x5a,0x04,0x9c,0xb8,0xd4,0x97,0x44, \
0x00,0x4b,0x8c,0x50,0xc0,0x06,0xa4,0x7a,0x00,0xe5,0xac,0x26,0x8b, \
0x35,0x3d,0xe5,0xd6,0x56,0x45,0x09,0x0b,0x8d,0x20,0x62,0xa0,0xc3, \
0x07,0xfe,0xb6,0xe2,0x89,0xae,0xa4,0x62,0x3a,0x24,0x38,0x0d,0x57, \
0x6a,0x00,0x93,0x0f,0x34,0x20,0x02,0x08,0xf1,0x00,0x01,0x80,0xa1, \
0x81,0x04,0x44,0xe0,0x02,0x47,0x8d,0x44,0x03,0x12,0x56,0x80,0x5e, \
0x86,0xd5,0x93,0x54,0x78,0x80,0x62,0x17,0xcb,0xd8,0xc6,0x3a,0xf6, \
0xb1,0x8a,0xcd,0x40,0xf7,0x22,0xa0,0x01,0x7e,0xc8,0x53,0x20,0x07, \
0xa8,0x6b,0x56,0xa0,0xf3,0x01,0x0d,0x00,0xa0,0x0b,0x81,0x10,0x00, \
0x03,0x20,0x90,0x01,0xa2,0xcd,0x81,0x9d,0x1e,0xed,0x98,0xd6,0x14, \
0xf0,0x51,0x7c,0x40,0x80,0x22,0x12,0x40,0xcf,0x68,0x13,0x01,0x51, \
0x87,0x1e,0xf6,0xb6,0x6f,0x60,0xe8,0xac,0xc0,0xfa,0x01,0x05,0x8c, \
0x43,0x04,0x02,0x88,0xcf,0x45,0xa3,0xa8,0xd6,0xb5,0xa8,0xcd,0x04, \
0x1b,0xc0,0x4a,0x01,0xf6,0xb1,0x92,0x05,0x3c,0x60,0x53,0xbf,0xe5, \
0x1e,0x6c,0x9c,0xa8,0x81,0x08,0x60,0x80,0x0a,0x8f,0xa7,0x10,0x00, \
0x6e,0xb7,0xfb,0x09,0x86,0x4e,0x80,0x78,0x1f,0x70,0x5b,0x34,0x24, \
0x30,0xcf,0x9f,0x55,0xc9,0xa3,0x4e,0xfc,0x00,0x47,0x4f,0xb0,0xcf, \
0x06,0x2c,0xa0,0x63,0x1f,0x08,0xae,0x04,0x26,0xf0,0x80,0x84,0xed, \
0x21,0x7c,0x11,0xb9,0x42,0x9f,0xa8,0x28,0x01,0x01,0x70,0x96,0xbb, \
0x00,0x46,0x81,0x70,0x00,0x50,0x5a,0x14,0x58,0x90,0x0c,0xc2,0xf1, \
0x05,0x35,0x2a,0x16,0x01,0x5b,0x10,0x63,0x67,0x21,0x9c,0x85,0x00, \
0x8a,0x00,0x8e,0x49,0x49,0x80,0x03,0x4c,0xfd,0x59,0x7a,0x1d,0x20, \
0x95,0x0c,0xc8,0x93,0xb8,0x01,0x0e,0x31,0x09,0x46,0xca,0x46,0x40, \
0x20,0xc9,0x2a,0x04,0x69,0x97,0xaf,0x7a,0x90,0xe2,0x95,0x9e,0xf8, \
0x3b,0x1d,0xb0,0x4f,0x89,0x42,0xe3,0x62,0xb3,0x38,0x60,0x49,0x44, \
0x31,0x40,0x0d,0x6e,0x6c,0x58,0x11,0x4b,0x32,0x04,0x00,0x3b,0x3b \
};
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex4/app.c
|
<reponame>nbarjolin/micrium_gnurx_cloud
/*
*********************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP.C
* By : FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#include "stdlib.h"
#include "iodefine.h"
#include "inthandler.h"
#include "rtadsplib.h" /* API header file for SP library */
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define APP_PWM_CARRIER_FREQ_HZ 20000L
#define APP_FFT_N_POINTS 1024
#define APP_DEADTIME 1u /* When no deadtime is required, set DEADTIME to 1 */
#define PI (CPU_FP32)3.141592654f
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_TCB AppTaskStartTCB;
static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static OS_TCB AppFFTTaskTCB;
static CPU_STK AppFFTTaskStk[APP_FFT_TASK_STK_SIZE];
static CPU_BOOLEAN AppTCPIP_Cfg = DEF_FALSE;
static CPU_FP32 AppPWM_ISR_Time_us; /* Execution time of PWM ISR */
/* FFT input data must start on an 8-byte boundary */
static CPU_FP32 AppADC_Array[APP_FFT_N_POINTS * 3] __attribute__ ((aligned (8)));
static CPU_INT16U AppADC_ArrayRMS[APP_FFT_N_POINTS / 4];
static CPU_FP32 AppFFT_FFT_Time_us; /* Execution time of FFT */
static CPU_FP32 AppFFT_Freq_Time_us; /* Execution time of actual frequency detection */
static CPU_FP32 AppFFT_RMS_Time_us; /* Execution time of RMS computation */
static CPU_FP32 AppTmrTS_To_us; /* CPU_TS to 'us' conversion factor */
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppFFTTask (void *p_arg);
static void AppPWM_Init (void);
static void AppADC_Init (void);
static void AppADC_TmrInit (void);
static void AppPWM_SetpointRd(void);
static void AppGraphLCD_Hdr (void);
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppTCPIP_Init (NET_ERR *perr);
void AppCloud_Init (CPU_BOOLEAN disableStatus);
#endif
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
void AppProbe_Init (void);
#endif
#define EX_LED_ON(a) {if (AppCloudControlLedOn) LED_On(a); else LED_Off(a);}
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
volatile CPU_INT08U AppFreqSetpointSel = 0; /* Variable which controls whether the target sine ... */
/* ... wave frequency to generate comes from the ... */
/* ... potentiometer or uC/Probe: */
/* ... (0 = Pot, 1 = uC/Probe) */
volatile CPU_INT16U AppFreqActualHz = 50;
volatile CPU_FP32 AppFreqSetpoint = 3.6f;
volatile CPU_INT16U AppFreqSetpointHz = 100;
volatile CPU_INT16U AppFreqSetpointPotHz = 100;
volatile CPU_INT16U AppFreqSetpointProbeHz = 100;
volatile CPU_INT08U AppCloudControlLedOn = 1;
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main (void)
{
OS_ERR err;
CPU_IntDis(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
App_OS_SetAllHooks();
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) 0,
(OS_PRIO ) APP_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while (1) {
;
}
return (0);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
CPU_CHAR str_lcd[20];
OS_ERR err;
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
NET_ERR net_err;
#endif
(void)&p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */
#if (OS_CFG_STAT_TASK_EN > 0u)
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
AppProbe_Init(); /* Initialize uC/Probe modules */
#endif
OSTaskCreate((OS_TCB *)&AppFFTTaskTCB, /* Create the start task */
(CPU_CHAR *)"FFT Task",
(OS_TASK_PTR ) AppFFTTask,
(void *) 0,
(OS_PRIO ) APP_FFT_TASK_PRIO,
(CPU_STK *)&AppFFTTaskStk[0],
(CPU_STK_SIZE) APP_FFT_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_FFT_TASK_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
BSP_GraphLCD_Init();
AppGraphLCD_Hdr();
if (CPU_TS_TmrFreq_Hz > 0) {
AppTmrTS_To_us = (CPU_FP32)1000000.0f / (CPU_FP32)CPU_TS_TmrFreq_Hz;
} else {
AppTmrTS_To_us = (CPU_FP32)0.0f;
}
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
if (net_err == NET_ERR_NONE) {
AppTCPIP_Cfg = DEF_TRUE;
}
#else
AppTCPIP_Cfg = DEF_TRUE;
#endif
AppCloud_Init(0);
/* Display TCP/IP data for several seconds */
OSTimeDlyHMSM(0u, 0u, 10u, 0u,
OS_OPT_TIME_HMSM_STRICT,
&err);
BSP_GraphLCD_Clear();
AppGraphLCD_Hdr();
while (DEF_ON) {
BSP_GraphLCD_ClrLine(5);
BSP_GraphLCD_ClrLine(6);
BSP_GraphLCD_ClrLine(7);
if (AppFreqSetpointSel == 0){
BSP_GraphLCD_String(5, "SRC: Pot");
} else {
BSP_GraphLCD_String(5, "SRC: uC/Probe");
}
Str_Copy(str_lcd, "Desired Freq: ");
Str_FmtNbr_Int32U(AppFreqSetpointHz,
3u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&str_lcd[14]);
Str_Cat(str_lcd, "Hz");
BSP_GraphLCD_String(6, str_lcd);
Str_Copy(str_lcd, "Actual Freq: ");
Str_FmtNbr_Int32U(AppFreqActualHz,
3u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&str_lcd[14]);
Str_Cat(str_lcd, "Hz");
BSP_GraphLCD_String(7, str_lcd);
OSTimeDlyHMSM(0u, 0u, 0u, 250u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
/*
*********************************************************************************************************
* AppTaskFFT()
*
* Description : This task waits for the ADC1 ISR to post its task semaphore signalling that
* ADC data has been collected which is subject to FFT analysis
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) A task semaphore is used to signal the event
*********************************************************************************************************
*/
static void AppFFTTask (void *p_arg)
{
OS_ERR err;
CPU_TS ts;
CPU_INT16U idx;
volatile CPU_INT16U max_idx;
volatile CPU_INT16U max;
CPU_INT32U t1;
CPU_INT32U t2;
CPU_INT32U t3;
CPU_TS ts_start;
CPU_FP32 *fft_twiddlefac;
RTA_DSPLIB_STATUS status;
CPU_SR_ALLOC();
(void)&p_arg;
/* Buf req'd to store sin/cos val of twiddle factor */
fft_twiddlefac = (CPU_FP32 *)(AppADC_Array + APP_FFT_N_POINTS);
Mem_Clr(AppADC_Array, sizeof(AppADC_Array));
rta_initfft(APP_FFT_N_POINTS, fft_twiddlefac); /* Initialize the FFT library */
AppPWM_Init();
AppADC_Init();
AppPWM_SetpointRd(); /* Read desired sine wave frequency (i.e. setpoint) */
AppADC_TmrInit(); /* Initialize ADC trigger timer */
while (DEF_ON) { /* Task body, always written as an infinite loop. */
OSTaskSemPend(0u, /* Wait for ADC conversion (and array is full) */
OS_OPT_PEND_BLOCKING,
&ts,
&err);
ts_start = CPU_TS_Get32();
/* Complex fwd FFT */
/* Computes fwd transform of a complex data sequence */
/* Complex fwd FFT performance measure start point */
status = rta_cfft1d((CPU_FP32 *)&AppADC_Array[0],
-1,
APP_FFT_N_POINTS / 2u,
fft_twiddlefac);
AppFFT_FFT_Time_us = (CPU_FP32)(CPU_TS_Get32() - ts_start) * AppTmrTS_To_us;
/* From APP_FFT_N_POINTS / 2 number of samples ... */
/* ... FFT func will output APP_FFT_N_POINTS / 2 ... */
/* ... real/complex data pairs. */
/* Performing a root mean square on these values ... */
/* ... gives the magnitudes we require. */
ts_start = CPU_TS_Get32();
for (idx = 0; idx < APP_FFT_N_POINTS / 2; idx += 2) {
t1 = abs(AppADC_Array[idx]);
t1 /= 2;
t1 *= t1;
t1 /= 2;
t2 = abs(AppADC_Array[idx + 1]);
t2 /= 2;
t2 *= t2;
t2 /= 2;
t3 = sqrt(t1 + t2);
AppADC_ArrayRMS[idx / 2] = t3;
}
AppFFT_RMS_Time_us = (CPU_FP32)(CPU_TS_Get32() - ts_start);
ts_start = CPU_TS_Get32();
max_idx = 0;
max = 0;
/* Scan array for maximum frequency */
/* Each array element corresponds to 1Hz */
/* As input frequency range is 50Hz to 200Hz, */
/* only frequencies in this range need be searched for. */
for (idx = 1; idx < ((APP_FFT_N_POINTS / 2) / 2); idx++){
if (AppADC_ArrayRMS[idx] > max){
max = AppADC_ArrayRMS[idx];
max_idx = idx;
}
}
AppFreqActualHz = max_idx; /* Each array element corresponds to 1 Hz */
AppFFT_Freq_Time_us = (CPU_FP32)(CPU_TS_Get32() - ts_start) * AppTmrTS_To_us;
AppPWM_SetpointRd(); /* Read desired sine wave frequency (i.e. setpoint) */
MTUA.TSTR.BIT.CST0 = 1; /* Restart ADC timer trigger */
}
}
/*
*********************************************************************************************************
* AppPWM_Init()
*
* Description : Function to initialise MTU channel 4 to operate in Complimentary PWM mode.
* PWM signal is output on MTIOC4B. Initial duty set to 0%.
*
* Arguments : none
*
* Returns : none
*
* Notes : 1) PWM base frequency set by MTU2 channel 3 TGRA register
* : 2) PWM duty controlled by MTU2 channel 4 TGRB register
*
* |
* TGRA_3 |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _
* | /\ /\
* | / \ / \
* | / \ / \
* TGRB_4 |_ _/_ _ _ \_ _ _ /_ _ _ \
* | /| |\ /| |\
* | / | | \ / | | \ /
* |/__|______|__\/__|______|__\/_
* | | | |
* |______| |______|
* MTIOC4B ____| |______| |____
*
*********************************************************************************************************
*/
static void AppPWM_Init (void)
{
MSTP_MTU3 = 0; /* Enable MTU3 - disable module stop mode */
MSTP_MTU4 = 0; /* Enable MTU4 - disable module stop mode */
IOPORT.PFCMTU.BIT.MTUS5 = 1; /* Use P54 as MTIOC4B-B pin */
MTUA.TSTR.BIT.CST3 = 0; /* Stop MTU3 */
MTUA.TSTR.BIT.CST4 = 0; /* Stop MTU3 */
MTU3.TCR.BIT.CKEG = 0; /* MTU3 count at rising edge of clock */
MTU4.TCR.BIT.CKEG = 0; /* MTU4 count at rising edge of clock */
MTU3.TCR.BIT.CCLR = 0; /* MTU3 counter clearing disabled */
MTU4.TCR.BIT.CCLR = 0; /* MTU4 counter clearing disabled */
MTU3.TCR.BIT.TPSC = 0; /* MTU3 internal clock counts on PCLK */
MTU4.TCR.BIT.TPSC = 0; /* MTU4 internal clock counts on PCLK */
MTU3.TCNT = APP_DEADTIME; /* Deadtime */
MTUA.TDDR = APP_DEADTIME;
MTU4.TCNT = 0;
MTUA.TDER.BIT.TDRE = 0; /* No deadtime generated */
/* Set carrier frequency */
MTUA.TCBR = ((BSP_CPU_EXT_CLK_FREQ * 4) / APP_PWM_CARRIER_FREQ_HZ) / 2;
MTUA.TCDR = ((BSP_CPU_EXT_CLK_FREQ * 4) / APP_PWM_CARRIER_FREQ_HZ) / 2;
MTU3.TGRA = (((BSP_CPU_EXT_CLK_FREQ * 4) / APP_PWM_CARRIER_FREQ_HZ) / 2) + APP_DEADTIME;
MTU3.TGRC = (((BSP_CPU_EXT_CLK_FREQ * 4) / APP_PWM_CARRIER_FREQ_HZ) / 2) + APP_DEADTIME;
MTUA.TOCR1.BIT.OLSP = 1; /* Initial output - low, high on up count compare match */
MTUA.TOCR1.BIT.OLSN = 0; /* Initial output - high, low on up count compare match */
MTUA.TOCR2.BIT.OLS3P = 1; /* Initial output - low, high on up count compare match */
MTU4.TIORH.BIT.IOB = 7;
MTU3.TMDR.BIT.MD = 0x0D; /* Complimentary PWM mode 1 (transfer at crest) */
MTU3.TMDR.BIT.BFB = 1; /* TGRD buffers TGRB */
MTUA.TOER.BIT.OE4B = 1; /* Enable MTIOC4B as MTU output */
IPR(MTU3, TGIA3) = 3; /* Set interrupt priority. */
IEN(MTU3, TGIA3) = 1; /* Enable interrupt source. */
MTU3.TIER.BIT.TGIEA = 1; /* Enable MTU3 TGIA interrupt */
MTUA.TSTR.BYTE = MTUA.TSTR.BYTE | 0xC0; /* Synchronously start channels 3 and 4 */
}
/*
*********************************************************************************************************
* AppPWM_SetpointRd()
*
* Description : Determine the setpoint
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
static void AppPWM_SetpointRd (void)
{
CPU_INT16U temp;
switch (AppFreqSetpointSel) {
case 1: /* Setpoint using uC/Probe ---------------------------- */
if (AppFreqSetpointProbeHz < 50) { /* Limit setpoint to between 50 and 200 Hz */
AppFreqSetpoint = 50;
} else if (AppFreqSetpointProbeHz > 200){
AppFreqSetpoint = 200;
} else {
AppFreqSetpointHz = (CPU_INT16U)AppFreqSetpointProbeHz;
AppFreqSetpoint = AppFreqSetpointProbeHz / 55.5556f;
}
break;
case 0:
default: /* Setpoint using Potentiometer ----------------------- */
temp = 4095 - (S12AD.ADDRE); /* Read POT ADC value and scale */
temp = temp / 14;
temp = temp + 100;
AppFreqSetpoint = 360.0f / (CPU_FP32)temp;
AppFreqSetpointPotHz = (CPU_INT16U)(AppFreqSetpoint * 55.5556f);
AppFreqSetpointHz = (CPU_INT16U)AppFreqSetpointPotHz;
break;
}
}
/*
*********************************************************************************************************
* AppPWM_ISR()
*
* Description : This function corresponds to the ISR of MTU, channel 3 TGIA.
*
* Arguments : none
*
* Returns : none
*
* Notes : Reads ADC value or uC/Probe updated variable, calculates next compare match B value and
* loads register.
*********************************************************************************************************
*/
void AppPWM_ISR (void)
{
CPU_INT16U temp;
static CPU_FP32 sine_idx = 360.0f;
static CPU_FP32 step;
CPU_TS_TMR ts_start;
ts_start = CPU_TS_TmrRd();
if (sine_idx >= 360.0f){
sine_idx = 0.0f; /* 'AppFreqSetpoint' is global */
step = (CPU_FP32)AppFreqSetpoint; /* 100 to 400 samples equates to 50 to 200 Hz sinewave */
}
temp = (CPU_INT16U)((BSP_CPU_EXT_CLK_FREQ * 4) / (2 * APP_PWM_CARRIER_FREQ_HZ) * sin(sine_idx * (PI / 180.0f)));
temp += (BSP_CPU_EXT_CLK_FREQ * 4) / (2 * APP_PWM_CARRIER_FREQ_HZ);
sine_idx += step;
MTU4.TGRD = temp / 2; /* Divide by 2 as max cnt is half PWM carrier cycle */
AppPWM_ISR_Time_us = (CPU_FP32)(CPU_TS_TmrRd() - ts_start) * AppTmrTS_To_us;
}
/*
*********************************************************************************************************
* AppADC_TmrInit()
*
* Description : Function to initialise MTU channel 0 to operate in normal mode. This timer triggers ADC
* conversions.
*
* Arguments : none
*
* Returns : none
*
* Notes : none
*********************************************************************************************************
*/
static void AppADC_TmrInit (void)
{
MSTP_MTU0 = 0; /* Enable MTU0 - disable module stop mode */
MTU0.TCR.BIT.TPSC = 3; /* Internal Pclk/64 clock source */
MTU0.TCR.BIT.CCLR = 1; /* Counter cleared on TGRA compare match */
MTU0.TMDR.BIT.MD = 0; /* Normal mode */
/* Compare match value - 512 Hz */
MTU0.TGRA = (CPU_INT16U)((BSP_CPU_EXT_CLK_FREQ * 4) / (64 * 512));
MTU0.TIER.BIT.TTGE = 1; /* ADC converter start request */
MTUA.TSTR.BIT.CST0 = 1; /* Start timer */
}
/*
*********************************************************************************************************
* AppADC_Init()
*
* Description : Function to initialise ADC 1.
* Conversion triggered by MTU2
*
* Arguments : none
*
* Returns : none
*
* Notes : AN4 - Input from POT1
* : AN7 - Input from MTU2 generated sine wave
*
* : Conversion end interrupt used to transfer AN7 ADC values to buffer for
* : FFT analysis
*********************************************************************************************************
*/
static void AppADC_Init (void)
{
MSTP_S12AD = 0; /* Enable S12AD 12-bit ADC - disable module stop mode */
S12AD.ADCSR.BIT.ADST = 0; /* Stop ADC */
S12AD.ADCSR.BIT.ADCS = 0; /* Single-scan mode */
S12AD.ADCSR.BIT.ADIE = 1; /* Conversion interrupt enabled */
S12AD.ADCSR.BIT.TRGE = 1; /* Trigger by external source */
S12AD.ADCSR.BIT.EXTRG = 0; /* Trigger by MTU2 or MTU2S */
S12AD.ADANS.BIT.ANS = (1 << 4) | (1 << 7); /* Enable AN4 & AN7 channels */
IPR(S12AD, ADI) = 3; /* Set interrupt priority. */
IEN(S12AD, ADI) = 1; /* Enable interrupt source. */
S12AD.ADSTRGR.BIT.ADSTRS = 1; /* Trigger by MTU0 compare match A */
PORT4.ICR.BIT.B4 = 1; /* P44 input routed to peripheral */
PORT4.ICR.BIT.B7 = 1; /* P47 input routed to peripheral */
}
/*
*********************************************************************************************************
* AppADC_ISR_ConversionHandler()
*
* Description : ADC ADI ISR.
*
* Arguments : none
*
* Returns : none
*
* Notes : 1) Copies AN7 value into array and signals FFT task when specified number of transfers
* : have occured.
* : 2) This periodic interrupt is used to "rotate" the LED motor display at a speed
* controlled by the measure frequency of the sine wave.
* : 3) This interrupt occurs at 512 Hz
*
*********************************************************************************************************
*/
void AppADC_ISR_ConversionHandler (void)
{
static CPU_INT16U adc_array_idx = 0;
static CPU_INT16U led_dly = 0;
static CPU_INT08U led_idx = 4;
OS_ERR err;
AppADC_Array[adc_array_idx++] = (CPU_FP32)S12AD.ADDRH;
AppADC_Array[adc_array_idx++] = (CPU_FP32)0.0f;
if (adc_array_idx == APP_FFT_N_POINTS) {
adc_array_idx = 0;
MTUA.TSTR.BIT.CST0 = 0; /* Stop ADC trigger timer */
OSTaskSemPost(&AppFFTTaskTCB, /* Signal task for FFT analysis */
OS_OPT_POST_NONE,
&err);
}
if (led_dly == 0) { /* Turn on appropriate LED */
EX_LED_ON(led_idx);
EX_LED_ON(led_idx + 6);
led_idx++;
if (led_idx == 10){
led_idx = 4;
}
LED_Off(led_idx);
LED_Off(led_idx + 6);
led_dly = 5000 / AppFreqActualHz;
}
led_dly--;
}
/*
*********************************************************************************************************
* AppGraphLCD_Hdr()
*********************************************************************************************************
*/
static void AppGraphLCD_Hdr (void)
{
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_LARGE);
BSP_GraphLCD_StringPos(0, 4, "Micrium");
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SMALL);
BSP_GraphLCD_StringPos(1, 5, "uC/OS-III");
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
BSP_GraphLCD_StringPos(2, 5, "uC/TCP-IP");
#endif
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/uC-Exosite/flash_api_rx600.c
|
<reponame>nbarjolin/micrium_gnurx_cloud<filename>uCOS-III-Ex6/uC-Exosite/flash_api_rx600.c
/******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corp. and is
* only intended for use with Renesas products.
* No other uses are authorized.
* This software is owned by Renesas Electronics Corp. and is
* protected under the applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES
* REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY,
* INCLUDING BUT NOT LIMITED TO WAWRRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. ALL SUCH
* WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER
* RENESAS ELECTRONICS CORP. NOR ANY OF ITS AFFILIATED COMPANIES
* SHALL BE LIABLE FOR AND DIRECT, INDIRECT, SPECIAL, INCIDENTAL
* OR COSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE,
* EVEN IF RENESAS OR ITS AFFILIATES HAVE BEEN ADVISED OF THE
* POSSIBILITIES OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this
* software and to discontinue availability of this software.
* By using this software, you agree to the additional terms and
* conditions found by accessing the following link:
* http://www.renesas.com/disclaimer
*******************************************************************************/
/* Copyright (C) 2010. Renesas Electronics Corp., All Rights Reserved */
/******************************************************************************
* File Name : Flash_API_RX600.c
* Version : 1.42
* Device(s) : R5F562N8
* Tool-Chain : Renesas RX Standard Toolchain 1.0.1
* OS : None
* H/W Platform : YRDKRX62N
* Description : Flash programming for the RX600 Group
* Limitations : None
*******************************************************************************
* History : DD.MMM.YYYY Version Description
* : 21.Dec.2009 1.00 First Release
* : 13.Jan.2010 1.10 Made function names and variables RAPI compliant
* : 11.Feb.2010 1.20 Fixed other RAPI issues and fixed I flag issue
* : 29.Apr.2010 1.30 Added support for RX621/N Group. Moved most
* device specific data to header file.
* : 26.May.2010 1.40 Added support for RX62T Group
* : 28.Jul.2010 1.41 Fixed bug when performing a blank check on an
* entire data flash block. Also declared
* functions not in the API as 'static'.
* : 23.Aug.2010 1.42 Updated source to raise the coding standard, to
* meet GSCE & RDK standards.
*******************************************************************************/
/******************************************************************************
Includes <System Includes> , "Project Includes"
******************************************************************************/
/* Intrinsic functions of MCU */
//#include <machine.h>
#include <cpu.h>
#include <os.h>
/* Function prototypes and device specific info needed for Flash API */
#include "flash_api_rx600.h"
/* Device specific SFR definitions */
#if defined(RX610)
#include "iodefine_RX610.h"
#elif defined(RX62N)
// #include "iodefine_RX62N.h"
// #include "iodefine_RPDL.h"
#include "iodefine.h"
#elif defined(RX621)
#include "iodefine_RX62N.h"
#elif defined(RX62T)
#include "iodefine_RX62N.h"
#else
#error "!!! You must specify your device in Flash_API_RX600.h first !!!"
#endif
/******************************************************************************
Typedef definitions
******************************************************************************/
/******************************************************************************
Macro definitions
******************************************************************************/
/* Define read mode macro */
#define READ_MODE 0
/* Define ROM PE mode macro */
#define ROM_PE_MODE 1
/* Define data flash PE mode macro */
#define FLD_PE_MODE 2
/* The number of ICLK ticks needed for 35us delay are calculated below */
#define WAIT_tRESW (35*ICLK_FREQUENCY)
/* The number of ICLK ticks needed for 10us delay are calculated below */
#define WAIT_t10USEC (10*ICLK_FREQUENCY)
/* This macro was defined in the Flash_API_RXxxx.h file and will
create an array of flash addresses called block_addresses. It is
used for getting the write addresses of flash blocks */
DEFINE_ADDR_LOOKUP
/******************************************************************************
Exported global variables and functions (to be accessed by other files)
******************************************************************************/
/* Signals whether FCU firmware has been transferred to the FCU RAM
0 : No, 1 : Yes */
uint8_t fcu_transfer_complete = 0;
/******************************************************************************
Private global variables and functions
******************************************************************************/
/* Valid values are 'READ_MODE','ROM_PE_MODE' or 'FLD_PE_MODE' */
static uint8_t current_mode;
/* Stores whether interrupts were enabled when flash operation was called */
static uint8_t psw_i_bit;
/* Flash intialisation function prototype */
static uint8_t _Flash_Init(void);
/* Enter PE mode function prototype */
static uint8_t _Enter_PE_Mode( uint32_t flash_addr, uint16_t bytes );
/* Exit PE mode function prototype */
static void _Exit_PE_Mode(void);
/* ROM write function prototype */
static uint8_t _ROM_Write(uint32_t address, uint32_t data);
/* Data flash write function prototype */
static uint8_t _DataFlash_Write(uint32_t address, uint32_t data, uint8_t size);
/* Data flash status clear function prototype */
static void _DataFlash_Status_Clr(void);
/* Notify peripheral clock function prototype */
static uint8_t _Notify_Peripheral_Clock(volatile uint8_t * flash_addr);
/* FCU reset function prototype */
static void _Flash_Reset(void);
/******************************************************************************
* Function Name: _Flash_Init
* Description : Initializes the FCU peripheral block.
NOTE: This function does not have to execute from in RAM.
* Arguments : none
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
******************************************************************************/
static uint8_t _Flash_Init(void)
{
/* Declare source and destination pointers */
uint32_t * src, * dst;
/* Declare iteration counter variable */
uint16_t i;
/* Disable FCU interrupts */
FLASH.FRDYIE.BIT.FRDYIE = 0;
/* Disable FCU interrupts in FCU block */
FLASH.FAEINT.BIT.ROMAEIE = 0;
FLASH.FAEINT.BIT.CMDLKIE = 0;
FLASH.FAEINT.BIT.DFLAEIE = 0;
FLASH.FAEINT.BIT.DFLRPEIE = 0;
FLASH.FAEINT.BIT.DFLWPEIE = 0;
/* Disable FCU interrupts in ICU */
/* Disable flash interface error (FIFERR) */
IPR(FCU, FIFERR) = 0;
IEN(FCU, FIFERR) = 0;
/* Disable flash ready interrupt (FRDYI) */
IPR(FCU, FRDYI) = 0;
IEN(FCU, FRDYI) = 0;
/* Transfer Firmware to the FCU RAM. To use FCU commands, the FCU firmware
must be stored in the FCU RAM. */
/* Before writing data to the FCU RAM, clear FENTRYR to stop the FCU. */
if (FLASH.FENTRYR.WORD != 0x0000)
{
/* Disable the FCU from accepting commands - Clear both the
FENTRY0(ROM) and FENTRYD(Data Flash) bits to 0 */
FLASH.FENTRYR.WORD = 0xAA00;
}
/* Enable the FCU RAM */
FLASH.FCURAME.WORD = 0xC401;
/* Copies the FCU firmware to the FCU RAM.
Source: H'FEFFE000 to H'FF00000 (FCU firmware area)
Destination: H'007F8000 to H'007FA000 (FCU RAM area) */
/* Set source pointer */
src = (uint32_t *)FCU_PRG_TOP;
/* Set destination pointer */
dst = (uint32_t *)FCU_RAM_TOP;
/* Iterate for loop to copy the FCU firmware */
for ( i=0; i<(FCU_RAM_SIZE/4); i++)
{
/* Copy data from the source to the destination pointer */
*dst = *src;
/* Increment the source and destination pointers */
src++;
dst++;
}
/* FCU firmware transfer complete, set the flag to 1 */
fcu_transfer_complete = 1;
/* Return 0, no errors */
return 0;
}
/******************************************************************************
End of function _Exit_PE_Mode
******************************************************************************/
/******************************************************************************
* Function Name: _DataFlash_Status_Clr
* Description : Clear the status of the Data Flash operation.
NOTE: This function does not have to execute from in RAM.
* Arguments : none
* Return Value : none
******************************************************************************/
static void _DataFlash_Status_Clr(void)
{
/* Declare temporaty pointer */
volatile uint8_t *ptrb;
/* Set pointer to Data Flash to issue a FCU command if needed */
ptrb = (uint8_t *)(DF_ADDRESS);
/* Check to see if an error has occurred with the FCU. If set, then
issue a status clear command to bring the FCU out of the
command-locked state */
if (FLASH.FSTATR0.BIT.ILGLERR == 1)
{
/* FASTAT must be set to 0x10 before the status clear command
can be successfully issued */
if (FLASH.FASTAT.BYTE != 0x10)
{
/* Set the FASTAT register to 0x10 so that a status clear
command can be issued */
FLASH.FASTAT.BYTE = 0x10;
}
}
/* Issue a status clear command to the FCU */
*ptrb = 0x50;
}
/******************************************************************************
End of function _DataFlash_Status_Clr
******************************************************************************/
/******************************************************************************
* Function Name: _DataFlash_Write
* Description : Write either 8-bytes of 128-bytes to Data Flash area.
NOTE: This function does not have to execute from in RAM.
* Arguments :
address
The address (in the Data Flash programming area) to write the data to
data
The address of the data to write
size
The size of the data to write. Must be set to either '8' or '128'
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
******************************************************************************/
static uint8_t _DataFlash_Write(uint32_t address, uint32_t data, uint8_t size)
{
/* Declare wait counter variable */
int32_t wait_cnt;
/* Define loop iteration count variable */
uint8_t n = 0;
/* Check data size is valid */
if ((size == 128) || (size == 8))
{
/* Perform bit shift */
size = size >> 1;
/* Send command to data flash area */
*(volatile uint8_t *)DF_ADDRESS = 0xE8;
/* Specify data transfer size to data flash area */
*(volatile uint8_t *)DF_ADDRESS = size;
/* Iterate through the number of data bytes */
while (n++ < size)
{
/* Copy data from source address to destination area */
*(volatile uint16_t *)address = *(uint16_t *)data;
/* Increment data address by two bytes */
data += 2;
}
/* Write the final FCU command for programming */
*(volatile uint8_t *)(DF_ADDRESS) = 0xD0;
/* Set the wait counter with timeout value */
wait_cnt = WAIT_MAX_DF_WRITE;
/* Check if FCU has completed its last operation */
while (FLASH.FSTATR0.BIT.FRDY == 0)
{
/* Decrement the wait counter */
wait_cnt--;
/* Check if the wait counter has reached zero */
if (wait_cnt == 0)
{
/* Maximum time for writing a block has passed,
operation failed, reset FCU */
_Flash_Reset();
/* Return 1, operation failure */
return 1;
}
}
/* Check for illegal command or programming errors */
if ((FLASH.FSTATR0.BIT.ILGLERR == 1) || (FLASH.FSTATR0.BIT.PRGERR == 1))
{
/* Return 1, operation failure */
return 1;
}
}
/* Data size is invalid */
else
{
/*Return 1, operation failure */
return 1;
}
/* Return 0, operation success */
return 0;
}
/******************************************************************************
End of function _DataFlash_Write
******************************************************************************/
/******************************************************************************
* Function Name: R_FlashDataAreaBlankCheck
* Description :
NOTE: This function does not have to execute from in RAM.
* Arguments :
address
The address to check if is blank.
If the parameter 'size'=='BLANK_CHECK_8_BYTE', this should be set to an
8-byte address boundary.
If the parameter 'size'=='BLANK_CHECK_ENTIRE_BLOCK', this should be set
to a defined Data Block Number ('BLOCK_DB0', 'BLOCK_DB1', etc...)
size
This specifies if you are checking an 8-byte location, or an entire
block. You must set this to either 'BLANK_CHECK_8_BYTE' or
'BLANK_CHECK_ENTIRE_BLOCK'.
* Return Value :
0x00 = Blank
0x01 = Not Blank
0x02 = Operation Failed
******************************************************************************/
uint8_t R_FlashDataAreaBlankCheck(uint32_t address, uint8_t size)
{
/* Declare data flash pointer */
volatile uint8_t *ptrb;
/* Declare result container variable */
uint8_t result;
/* Set current FCU mode to Data Flash PE Mode */
current_mode = FLD_PE_MODE;
/* Enter Data Flash PE mode in the FCU */
if ( _Enter_PE_Mode( address, 0 ) != 0)
{
/* FCU failed to enter PE mode, set mode to READ */
current_mode = READ_MODE;
/* Return 2, operation failure */
return 2;
}
/* Set bit FRDMD (bit 4) in FMODR to 1 */
FLASH.FMODR.BIT.FRDMD = 1;
/* Check if 8 byte size has been passed */
if (size == BLANK_CHECK_8_BYTE)
{
/* Set data flash pointer to beginning of the memory block */
ptrb = (uint8_t *)(address & DF_MASK);
/* Check if the next 8 bytes are blank
Bits BCADR to the address of the 8-byte location
to check (only bits A3-A12).
Set bit BCSIZE in EEPBCCNT to 0. */
FLASH.DFLBCCNT.WORD = (uint16_t)(address & (DF_BLOCK_SIZE-8));
}
/* Check entire data block */
else
{
/* Any address in the erasure block */
ptrb = (uint8_t *)address;
/* Check if the entire block is blank
Set bit BCSIZE in EEPBCCNT to 1.
Bits BCADR are not used, set to '0'. */
FLASH.DFLBCCNT.WORD = 0x0001;
}
/* Send commands to FCU */
*ptrb = 0x71;
*ptrb = 0xD0;
/* Check 'FRDY' bit */
while ( FLASH.FSTATR0.BIT.FRDY == 0 )
{
/* Wait till ready */
}
/* Reset the FRDMD bit back to 0 */
FLASH.FMODR.BIT.FRDMD = 0x00;
/* Check if the 'ILGERR' was set during the command */
if (FLASH.FSTATR0.BIT.ILGLERR == 1) /* Check 'ILGERR' bit */
{
/* Take the FCU out of PE mode */
_Exit_PE_Mode( );
/* Set the FCU mode to READ */
current_mode = READ_MODE;
/* Return 2, operation failure */
return 2;
}
/* (Read the 'BCST' bit (bit 0) in the 'DFLBCSTAT' register
0=blank, 1=not blank */
result = FLASH.DFLBCSTAT.BIT.BCST;
/* Take the FCU out of PE mode */
_Exit_PE_Mode( );
/* Set the current mode to READ */
current_mode = READ_MODE;
/* Return 1/0 (Not Blank/Blank), operation successful */
return( result );
}
/******************************************************************************
End of function R_FlashDataAreaBlankCheck
******************************************************************************/
/******************************************************************************
* Function Name: R_FlashDataAreaAccess
* Description :
This function is used to allow read and program permissions to the Data
Flash areas.
NOTE: This function does not have to execute from in RAM.
* Arguments :
read_en_mask
Bitmasked value. Bits 0-3 represents each Data Blocks 0-3 (respectively).
'0'=no Read access. '1'=Allows Read by CPU
write_en_mask
Bitmasked value. Bits 0-3 represents each Data Blocks 0-3 (respectively).
'0'=no Erase/Write access. '1'=Allows Erase/Write by FCU
* Return Value : none
******************************************************************************/
void R_FlashDataAreaAccess(uint16_t read_en_mask, uint16_t write_en_mask)
{
#if defined(RX610)
/* Set Read access for the Data Flash blocks */
FLASH.DFLRE.WORD = 0x2D00 | (read_en_mask & 0x00FF);
/* Set Erase/Program access for the Data Flash blocks */
FLASH.DFLWE.WORD = 0x1E00 | (write_en_mask & 0x00FF);
#elif defined(RX621) || defined(RX62T) || defined(RX62N)
/* Set Read access for the Data Flash blocks DB0-DB7 */
FLASH.DFLRE0.WORD = 0x2D00 | (read_en_mask & 0x00FF);
/* Set Read access for the Data Flash blocks DB8-DB15 */
FLASH.DFLRE1.WORD = 0xD200 | ((read_en_mask >> 8) & 0x00FF);
/* Set Erase/Program access for the Data Flash blocks DB0-DB7 */
FLASH.DFLWE0.WORD = 0x1E00 | (write_en_mask & 0x00FF);
/* Set Erase/Program access for the Data Flash blocks DB8-DB15 */
FLASH.DFLWE1.WORD = 0xE100 | ((write_en_mask >> 8) & 0x00FF);
#else
#error "!!! You must specify your device in Flash_API_RX6xx.h first !!!"
#endif
}
#if ENABLE_ROM_PROGRAMMING
#pragma section FRAM
#endif
/******************************************************************************
End of function R_FlashDataAreaAccess
******************************************************************************/
/******************************************************************************
* Function Name: _ROM_Write
* Description : Write 256 bytes to ROM Area Flash.
NOTE: This function MUST execute from in RAM.
* Arguments : none
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
******************************************************************************/
static uint8_t _ROM_Write(uint32_t address, uint32_t data)
{
/* Declare iteration loop count variable */
uint8_t i;
/* Declare wait counter variable */
int32_t wait_cnt;
/* Write the FCU Program command */
*(volatile uint8_t *)address = 0xE8;
*(volatile uint8_t *)address = 0x80;
/* Write 256 bytes into flash, 16-bits at a time */
for (i = 0; i < 128; i++)
{
/* Copy data from source address to destination ROM */
*(volatile uint16_t *)address = *(uint16_t *)data;
/* Increment destination address by 2 bytes */
data += 2;
}
/* Write the final FCU command for programming */
*(volatile uint8_t *)address = 0xD0;
/* Set timeout wait counter value */
wait_cnt = WAIT_MAX_ROM_WRITE;
/* Wait until FCU operation finishes, or a timeout occurs */
while (FLASH.FSTATR0.BIT.FRDY == 0)
{
/* Decrement the wait counter */
wait_cnt--;
/* Check if the wait counter has reached zero */
if (wait_cnt == 0)
{
/* Maximum timeout duration for writing to ROM has elapsed -
assume operation failure and reset the FCU */
_Flash_Reset();
/* Return 1, operation failure */
return 1;
}
}
/* Check for illegal command or programming errors */
if ((FLASH.FSTATR0.BIT.ILGLERR == 1) || (FLASH.FSTATR0.BIT.PRGERR == 1))
{
/* Return 1, operation failure */
return 1;
}
/* Return 0, operation successful */
return 0;
}
/******************************************************************************
End of function _ROM_Write
******************************************************************************/
/******************************************************************************
* Function Name: _Enter_PE_Mode
* Description :
NOTE: This function MUST execute from in RAM for 'ROM Area' programming,
but if you are ONLY doing Data Flash programming, this function can reside
and execute in Flash.
* Arguments : bytes
The number of bytes you are writing (if you are writing). This argument
is used to determine if you are crossing the 1MB boundary in ROM. If you
do cross this boundary then FENTRY0 and FENTRY1 both need to be set.
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
******************************************************************************/
static uint8_t _Enter_PE_Mode( uint32_t flash_addr, uint16_t bytes )
{
OS_ERR err;
/* FENTRYR must be 0x0000 before bit FENTRY0 or FENTRYD can be set to 1 */
FLASH.FENTRYR.WORD = 0xAA00;
/* Execute null operations to allow FENTRYR register to settle */
// nop();
// nop();
OSTimeDly(3, OS_OPT_TIME_DLY, &err);
/* Check if FCU mode is set to ROM PE */
if ( current_mode == ROM_PE_MODE)
{
/* See if interrupts were already disabled, so as not to enable them
when leaving. Store interrupt enabled flag locally */
if (get_ipl() == 0) //Micrium interrupt enable
{
psw_i_bit = 1;
} else
{
psw_i_bit = 0;
}
/* Disable Interrupts because the interrupt vector table may not
be accessible */
// set_psw(get_psw() & (~I_FLAG));
CPU_IntDis();
/* Check which partition of flash this address is in */
if (flash_addr >= 0x00F00000)
{
/* Enter ROM PE mode for addresses 0xFFF00000 - 0xFFFFFFFF */
FLASH.FENTRYR.WORD = 0xAA01;
} else
{
/* Enter ROM PE mode for addresses 0xFFE00000 - 0xFFEFFFFF */
FLASH.FENTRYR.WORD = 0xAA02;
}
}
/* Check if FCU mode is set to data flash PE */
else if ( current_mode == FLD_PE_MODE )
{
/* Set FENTRYD bit(Bit 7) and FKEY (B8-15 = 0xAA) */
FLASH.FENTRYR.WORD = 0xAA80;
/* First clear the FCU's status before doing Data Flash programming.
This is to clear out any previous errors that may have occured.
For example, if you attempt to read the Data Flash area
before you make it readable using R_FlashDataAreaAccess(). */
_DataFlash_Status_Clr();
}
/* Catch-all for invalid FCU mode */
else
{
/* Invalid value of 'current_mode' */
return 1;
}
/* Enable Write/Erase of ROM/Data Flash */
FLASH.FWEPROR.BYTE = 0x01;
/* Check for FCU error */
if ( (FLASH.FSTATR0.BIT.ILGLERR == 1)
|| (FLASH.FSTATR0.BIT.ERSERR == 1)
|| (FLASH.FSTATR0.BIT.PRGERR == 1)
|| (FLASH.FSTATR1.BIT.FCUERR == 1))
{
/* Enable Interrupts if I flag was set initially (ROM PE Mode only) */
if (psw_i_bit == 1)
{
/* Restore original interrupt enable flag status */
// set_psw(get_psw() | (I_FLAG));
CPU_IntEn();
}
/* Return 1, operation failure */
return 1;
}
/* Return 0, operation successful */
return 0;
}
/******************************************************************************
End of function _Enter_PE_Mode
******************************************************************************/
/******************************************************************************
* Function Name: _Exit_PE_Mode
* Description :
NOTE: This function MUST execute from in RAM for 'ROM Area' programming,
but if you are ONLY doing Data Flash programming, this function can reside
and execute in Flash.
* Arguments : none
* Return Value : none
******************************************************************************/
static void _Exit_PE_Mode( void )
{
/* Declare wait timer count variable */
int32_t wait_cnt;
/* Declare address pointer */
volatile uint8_t *pAddr;
/* Set wait timer count duration */
wait_cnt = WAIT_MAX_ERASE;
/* Iterate while loop whilst FCU operation is in progress */
while (FLASH.FSTATR0.BIT.FRDY == 0)
{
/* Decrement wait timer count variable */
wait_cnt--;
/* Check if wait timer count value has reached zero */
if (wait_cnt == 0)
{
/* Timeout duration has elapsed, assuming operation failure and
resetting the FCU */
_Flash_Reset();
/* Break from the while loop prematurely */
break;
}
}
/* Check FSTATR0 and execute a status register clear command if needed */
if ( (FLASH.FSTATR0.BIT.ILGLERR == 1)
|| (FLASH.FSTATR0.BIT.ERSERR == 1)
|| (FLASH.FSTATR0.BIT.PRGERR == 1))
{
/* Clear ILGLERR */
if (FLASH.FSTATR0.BIT.ILGLERR == 1)
{
/* FASTAT must be set to 0x10 before the status clear command
can be successfully issued */
if (FLASH.FASTAT.BYTE != 0x10)
{
/* Set the FASTAT register to 0x10 so that a status clear
command can be issued */
FLASH.FASTAT.BYTE = 0x10;
}
}
/* Issue a status register clear command to clear all error bits */
if ( current_mode == ROM_PE_MODE )
{
/* Set address pointer to ROM area */
pAddr = (uint8_t *)ROM_PE_ADDR;
/* Send status clear command to FCU */
*pAddr = 0x50;
} else
{
/* Set address pointer to data flash area */
pAddr = (uint8_t *)DF_ADDRESS;
/* Send status clear command to FCU */
*pAddr = 0x50;
}
}
/* Enter ROM Read mode */
FLASH.FENTRYR.WORD = 0xAA00;
/* Flash write/erase disabled */
FLASH.FWEPROR.BYTE = 0x02;
/* Restore the imask value (ROM PE Mode only) */
if ( current_mode == ROM_PE_MODE )
{
/* Enable Interrupts if I flag was set initially (ROM PE Mode only) */
if (psw_i_bit == 1)
{
/* Restore original interrupt enable flag status */
// set_psw(get_psw() | (I_FLAG));
CPU_IntEn();
}
}
}
/******************************************************************************
End of function R_FlashErase
******************************************************************************/
/******************************************************************************
* Function Name: R_FlashErase
* Description : Erases an entire flash block.
NOTE: This function MUST execute from in RAM for 'ROM Area' programming,
but if you are ONLY doing Data Flash programming, this function can reside
and execute in Flash.
* Arguments :
block
The block number to erase (BLOCK_0, BLOCK_1, etc...)
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
******************************************************************************/
uint8_t R_FlashErase (uint8_t block)
{
/* Declare address pointer */
volatile uint8_t *pAddr;
/* Declare erase operation result container variable */
uint8_t result = 0;
/* Declare timer wait count variable */
int32_t wait_cnt;
/* Erase Command Address */
pAddr = (volatile uint8_t *)(block_addresses[ block ]);
/* Check for FCU operation to complete */
if ( !fcu_transfer_complete )
{
/* Initialise the FCU, and store operation resilt in result variable */
result = _Flash_Init();
/* Check if FCU initialisation was successful */
if ( result != 0x00 )
{
/* FCU initialisiation failed - return 1, operation failure */
return 1;
}
}
/* Make sure we are not in the middle of another operation */
if ( current_mode != READ_MODE )
{
/* Currently in the middle of doing something else */
return 1;
}
/* Do we want to erase a Data Flash block or ROM block? */
if ( block >= BLOCK_DB0 )
{
/* Set current FCU mode to data flash PE */
current_mode = FLD_PE_MODE;
} else
{
/* Set current FCU mode to ROM PE */
current_mode = ROM_PE_MODE;
}
/* Enter ROM PE mode, check if operation successful */
if ( _Enter_PE_Mode((uint32_t)pAddr, 0) != 0)
{
/* Enter PE mode operation failed, set current mode to READ */
current_mode = READ_MODE;
/* Return 1, operation failure */
return 1;
}
/* Inform FCU of peripheral clock speed, check if operation is succesful */
if ( _Notify_Peripheral_Clock(pAddr) != 0)
{
/* Notify operation failed, set FCU mode to READ */
current_mode = READ_MODE;
/* Return 1, operation failure */
return 1;
}
/* Cancel the ROM Protect feature
NOTE: If you are using block locking feature to protect your data,
remove the following line */
FLASH.FPROTR.WORD = 0x5501;
/* Send the FCU Command */
*pAddr = 0x20;
*pAddr = 0xD0;
/* Set the wait counter timeout duration */
wait_cnt = WAIT_MAX_ERASE;
/* Wait while FCU operation is in progress */
while (FLASH.FSTATR0.BIT.FRDY == 0)
{
/* Decrement the wait counter */
wait_cnt--;
/* Check if the wait counter has reached zero */
if (wait_cnt == 0)
{
/* Maximum timeout duration for erasing a ROM block has
elapsed, assuming operation failure - reset the FCU */
_Flash_Reset();
/* Return 1, operation failure */
return 1;
}
}
/* Check if erase operation was successful by checking
bit 'ERSERR' (bit5) and 'ILGLERR' (bit 6) of register 'FSTATR0' */
/* Check FCU error */
if ((FLASH.FSTATR0.BIT.ILGLERR == 1) || (FLASH.FSTATR0.BIT.ERSERR == 1))
{
result = 1;
}
/* Leave Program/Erase Mode */
_Exit_PE_Mode();
/* Set FCU mode to READ */
current_mode = READ_MODE;
/* Return erase result, operation succesful */
return result;
}
/******************************************************************************
End of function R_FlashErase
******************************************************************************/
/******************************************************************************
* Function Name: R_FlashWrite
* Description : Writes bytes into flash.
NOTE: This function MUST execute from in RAM for 'ROM Area' programming,
but if you are ONLY doing Data Flash programming, this function can reside
and execute in Flash.
* Arguments :
flash_addr
Flash address location to write to. This address must be on a 256 byte
boundary.
buffer_addr
Address location of data buffer to write into flash.
bytes
The number of bytes to write. You must always pass a multiple of 256
bytes for programming.
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
0x02 = (ROM AREA) Number of bytes is not divisible by 256
0x03 = (ROM AREA) Flash address not on a 256 byte boundary
0x04 = (Data Flash AREA) Number of bytes not divisible by 8
0x05 = (Data Flash AREA) Flash address not on 8 byte boundary
0x06 = Invalid address
0x07 = (ROM AREA) Cannot write over 1MB boundary at 0xFFF00000
******************************************************************************/
uint8_t R_FlashWrite ( uint32_t flash_addr, uint32_t buffer_addr,
uint16_t bytes )
{
/* Declare result container and number of bytes to write variables */
uint8_t result = 0, num_byte_to_write;
/* Take off upper byte since for programming/erase addresses for ROM are
the same as read addresses except upper byte is masked off to 0's.
Data Flash addresses are not affected. */
flash_addr &= 0x00FFFFFF;
/* ROM area or Data Flash area - Check for DF first */
if ( flash_addr >= DF_ADDRESS && flash_addr < DF_ADDRESS + DF_SIZE )
{
/* Check if the number of bytes were passed is a multiple of 8 */
if ( bytes & 0x07 )
{
/* Return 4, number of bytes not a multiple of 8 */
return 4;
}
/* Check for an address on a 8 byte page boundary. */
if ( (uint16_t)flash_addr & 0x07)
{
/* Return 5, address not on an 8 byte boundary */
return 5;
}
}
/* Check for ROM area */
else if ( (flash_addr >= ROM_PE_ADDR)
&& (flash_addr < ROM_PE_ADDR + ROM_SIZE) )
{
/* Check if the number of bytes were passed is a multiple of 256 */
if ( bytes & 0xFF )
{
/* Return 2, number of bytes not a multiple of 256 */
return 2;
}
/* Check for an address on a 256 byte page */
if ( (uint16_t)flash_addr & 0xFF)
{
/* Return 3, address not on a 256 byte boundary */
return 3;
}
/* Check for passing over 1MB boundary at 0xFFF00000 */
if ( (flash_addr < (0x00F00000))
&& ((flash_addr + bytes) > 0x00F00000) )
{
/* Return 7, cannot write across a 1MB boundary */
return 7;
}
} else
{
/* Return 6, invalid flash address */
return 6;
}
/* If FCU firmware has already been transferred to FCU RAM,
no need to do it again */
if ( !fcu_transfer_complete )
{
/* If FCU firmware has not been transferred,
then transfer from FCU ROM to FCU RAM. */
result = _Flash_Init();
}
/* Make sure we are not in the middle of another operation */
if ( current_mode != READ_MODE )
{
/* Flash operation in progress - return 1, operation failure */
return 1;
}
/* Do we want to program a DF area or ROM area? */
if ( flash_addr < block_addresses[ROM_NUM_BLOCKS-1] )
{
/* Set current FCU mode to data flash PE */
current_mode = FLD_PE_MODE;
} else
{
/* Set FCU to ROM PE mode */
current_mode = ROM_PE_MODE;
}
/* Enter PE mode, check if operation is successful */
if ( _Enter_PE_Mode( flash_addr, bytes ) != 0)
{
/* Mode change failure, set FCU mode to READ */
current_mode = READ_MODE;
/* Return 1, operation failure */
return 1;
}
/* Cancel the ROM Protect feature
NOTE: If you are using block locking feature to protect your data,
remove the following line */
FLASH.FPROTR.WORD = 0x5501;
/* Check if FCU mode is set to data flash PE */
if ( current_mode == FLD_PE_MODE )
{
/* Iterate while there are still bytes remaining to write */
while ( bytes )
{
/* Check if address is on a 128 byte boundary, and there are
at least 128 bytes remaining to write */
if ( (bytes >= 128) && (((uint8_t)flash_addr & 0x7F) == 0x00))
{
/* Set the next data transfer size to be 128 */
num_byte_to_write = 128;
} else
{ /* Set the next data transfer size to be 8 */
num_byte_to_write = 8;
}
/* Call the Programming function, store the operation status in the
container variable, result */
result = _DataFlash_Write( flash_addr, buffer_addr,
num_byte_to_write);
/* Check the container variable result for errors */
if ( result != 0x00 )
{
/* Data flash write error detected, break from flash write
while loop prematurely */
break;
}
/* Increment the flash address and the buffer address by the size
of the transfer thats just completed */
flash_addr += num_byte_to_write;
buffer_addr += num_byte_to_write;
/* Decrement the number of bytes remaining by the size of the last
flash write */
bytes -= num_byte_to_write;
}
}
/* Catch-all - FCU mode must be ROM PE */
else
{
/* Iterate loop while there are still bytes remaining to write */
while ( bytes )
{
/* Call the Programming function */
result = _ROM_Write(flash_addr, buffer_addr);
/* Check for errors */
if ( result != 0x00 )
{
/* Stop programming */
break;
}
/* Increment the flash address and the buffer address by the size
of the transfer thats just completed */
flash_addr += 256;
buffer_addr += 256;
/* Decrement the number of bytes remaining by the size of the last
flash write */
bytes -= 256;
}
}
/* Leave Program/Erase Mode */
_Exit_PE_Mode();
/* Set current FCU mode to READ */
current_mode = READ_MODE;
/* Return flash programming result */
return result;
}
/******************************************************************************
End of function R_FlashWrite
******************************************************************************/
/******************************************************************************
* Function Name: _Notify_Peripheral_Clock
* Description : Notifies FCU or Peripheral Clock (PCLK)
NOTE: This function MUST execute from in RAM for 'ROM Area' programming,
but if you are ONLY doing Data Flash programming, this function can reside
and execute in Flash.
* Arguments :
flash_addr
Flash address you will be erasing or writing to
* Return Value :
0x00 = Operation Successful
0x01 = Operation Failed
******************************************************************************/
static uint8_t _Notify_Peripheral_Clock(volatile uint8_t * flash_addr)
{
/* Declare wait counter variable */
int32_t wait_cnt;
/* Notify Peripheral Clock(PCK) */
/* Set frequency of PCK */
FLASH.PCKAR.WORD = PCLK_FREQUENCY;
/* Execute Peripheral Clock Notification Commands */
*flash_addr = 0xE9;
*flash_addr = 0x03;
*(volatile unsigned short *)flash_addr = 0x0F0F;
*(volatile unsigned short *)flash_addr = 0x0F0F;
*(volatile unsigned short *)flash_addr = 0x0F0F;
*flash_addr = 0xD0;
/* Set timeout wait duration */
wait_cnt = WAIT_t10USEC;
/* Check FRDY */
while (FLASH.FSTATR0.BIT.FRDY == 0)
{
/* Decrement wait counter */
wait_cnt--;
/* Check if wait counter has reached zero */
if (wait_cnt == 0)
{
/* Timeout duration elapsed, assuming operation failure - Reset
FCU */
_Flash_Reset();
/* Return 1, operation failure */
return 1;
}
}
/* Check ILGLERR */
if (FLASH.FSTATR0.BIT.ILGLERR == 1)
{
/* Return 1, operation failure*/
return 1;
}
/* Return 1, operation success */
return 0;
}
/******************************************************************************
End of function _Notify_Peripheral_Clock
******************************************************************************/
/******************************************************************************
* Function Name: _Flash_Reset
* Description : Reset the FCU.
NOTE: This function MUST execute from in RAM for 'ROM Area' programming,
but if you are ONLY doing Data Flash programming, this function can reside
and execute in Flash.
* Arguments : none
* Return Value : none
******************************************************************************/
static void _Flash_Reset(void)
{
/* Declare wait counter variable */
int32_t wait_cnt;
/* Reset the FCU */
FLASH.FRESETR.WORD = 0xCC01;
/* Give FCU time to reset */
wait_cnt = WAIT_tRESW;
/* Wait until the timer reaches zero */
while (wait_cnt != 0)
{
/* Decrement the timer count each iteration */
wait_cnt--;
}
/* FCU is not reset anymore */
FLASH.FRESETR.WORD = 0xCC00;
}
/******************************************************************************
End of function _Flash_Reset
******************************************************************************/
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib-Ex6/tftp-s_cfg.h
|
<filename>uCOS-III-Lib-Ex6/tftp-s_cfg.h
/*
*********************************************************************************************************
* uC/TFTPs
* Trivial File Transfer Protocol (server)
*
* (c) Copyright 2005-2010; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TFTPs is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* TFTP SERVER CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : tftp-s_cfg.h
* Version : V1.91.01
* Programmer(s) : JDH
* SR
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* TASKS PRIORITIES
*********************************************************************************************************
*/
#define TFTPs_OS_CFG_TASK_PRIO 7
/*
*********************************************************************************************************
* STACK SIZES
* Size of the task stacks (# of OS_STK entries)
*********************************************************************************************************
*/
#define TFTPs_OS_CFG_TASK_STK_SIZE 512
/*
*********************************************************************************************************
* TFTPs
*********************************************************************************************************
*/
#define TFTPs_CFG_IPPORT 69 /* TFTP server IP port. Default is 69. */
#define TFTPs_CFG_MAX_RX_TIMEOUT_MS 30000 /* Maximum inactivity time (ms) on RX. */
#define TFTPs_CFG_MAX_TX_TIMEOUT_MS 30000 /* Maximum inactivity time (ms) on TX. */
#define TFTPs_TRACE_HIST_SIZE 16 /* Trace history size. Minimum value is 16. */
/*
*********************************************************************************************************
* TRACING
*********************************************************************************************************
*/
#define TRACE_LEVEL_OFF 0
#define TRACE_LEVEL_INFO 1
#define TRACE_LEVEL_DBG 2
#define TFTPs_TRACE_LEVEL TRACE_LEVEL_OFF
#define TFTPs_TRACE printf
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/net_cfg.h
|
/*
*********************************************************************************************************
* uC/TCP-IP V2
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : net_cfg.h
* Version : V2.11.02
* Programmer(s) : ITJ
* SR
* SL
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK CONFIGURATION
*
* Note(s) : (1) (a) Configure NET_CFG_INIT_CFG_VALS with the desired configuration for the initialization
* of network protocol suite configurable parameters :
*
* NET_INIT_CFG_VALS_DFLT Configure network parameters with default values
* NET_INIT_CFG_VALS_APP_INIT Configure network parameters with application-
* initialized values (recalled from non-volatile
* memory &/or hard-coded in product's application)
*
* (b) (1) When NET_CFG_INIT_CFG_VALS is configured as NET_INIT_CFG_VALS_DFLT, the network
* protocol suite's configurable parameters are configured with default values.
*
* The application need only call Net_Init() to initialize both the network protocol
* suite & its configurable parameters.
*
* (2) When NET_CFG_INIT_CFG_VALS is configured as NET_INIT_CFG_VALS_APP_INIT, the
* application MUST ...
*
* (A) Initialize ALL network protocol suite configurable parameters from values
* recalled from non-volatile memory &/or hard-coded application values :
*
* (1) Call each of the configuration functions in Net_InitDflt() passing the
* application-recalled &/or hard-coded values
* OR
* (2) Call Net_InitDflt() to initialize ALL network protocol suite configurable
* parameters to their default values & then call any of the configuration
* functions in Net_InitDflt() passing the recalled &/or hard-coded values
* to initialize some of the network protocol suite configurable parameters
*
* (B) Call Net_Init()
*
* See also 'net.c Net_InitDflt() Notes #1 & #2'
* & 'net_def.h PARAMETER CONFIGURATION INITIALIZATION Note #1'.
*
* (2) (a) Configure NET_CFG_OPTIMIZE with the desired network performance optimization :
*
* NET_OPTIMIZE_SPD Optimizes network protocol suite for speed performance
* NET_OPTIMIZE_SIZE Optimizes network protocol suite for binary image size
*
* (b) Configure NET_CFG_OPTIMIZE_ASM_EN to enable/disable network protocol suite assembly
* optimization functions.
*
* (3) Configure NET_CFG_BUILD_LIB_EN to enable/disable building the network protocol suite as
* a linkable library.
*********************************************************************************************************
*/
/* Configure network protocol suite's configurable ... */
/* ... parameters' initial values (see Note #1) : */
#define NET_CFG_INIT_CFG_VALS NET_INIT_CFG_VALS_DFLT
/* NET_INIT_CFG_VALS_DFLT Default values */
/* NET_INIT_CFG_VALS_APP_INIT Application values */
/* Configure network protocol suite's performance ... */
/* ... optimization (see Note #2a) : */
#define NET_CFG_OPTIMIZE NET_OPTIMIZE_SPD
/* NET_OPTIMIZE_SPD Optimize for Speed */
/* NET_OPTIMIZE_SIZE Optimize for Size */
/* Configure network protocol suite's assembly ... */
/* ... optimization (see Note #2b) : */
#define NET_CFG_OPTIMIZE_ASM_EN DEF_DISABLED
/* DEF_DISABLED Assembly optimization DISABLED */
/* DEF_ENABLED Assembly optimization ENABLED */
/* Configure network protocol suite to build as a ... */
/* ... linkable library (see Note #3) : */
#define NET_CFG_BUILD_LIB_EN DEF_DISABLED
/* DEF_DISABLED Build as library DISABLED */
/* DEF_ENABLED Build as library ENABLED */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK DEBUG CONFIGURATION
*
* Note(s) : (1) Configure NET_DBG_CFG_INFO_EN to enable/disable network protocol suite debug information :
*
* (a) Internal constants assigned to global variables
* (b) Internal variable data sizes calculated & assigned to global variables
*
* (2) Configure NET_DBG_CFG_STATUS_EN to enable/disable network protocol suite debug status
* functions.
*
* (3) Configure NET_DBG_CFG_MEM_CLR_EN to enable/disable the network protocol suite from clearing
* internal data structure memory buffers; a convenient feature while debugging.
*
* (4) Configure NET_DBG_CFG_TEST_EN to enable/disable the network protocol suite test features :
*
* (a) Internal data structure test &/or control flags
* (b) Internal data structure read functionality
*********************************************************************************************************
*/
/* Configure debug information feature (see Note #1) : */
#define NET_DBG_CFG_INFO_EN DEF_DISABLED
/* DEF_DISABLED Debug information DISABLED */
/* DEF_ENABLED Debug information ENABLED */
/* Configure debug status functions (see Note #2) : */
#define NET_DBG_CFG_STATUS_EN DEF_DISABLED
/* DEF_DISABLED Debug status functions DISABLED */
/* DEF_ENABLED Debug status functions ENABLED */
/* Configure memory clear feature (see Note #3) : */
#define NET_DBG_CFG_MEM_CLR_EN DEF_DISABLED
/* DEF_DISABLED Data structure clears DISABLED */
/* DEF_ENABLED Data structure clears ENABLED */
/* Configure test/debug feature(s) (see Note #4) : */
#define NET_DBG_CFG_TEST_EN DEF_DISABLED
/* DEF_DISABLED Test/Debug features DISABLED */
/* DEF_ENABLED Test/Debug features ENABLED */
/*
*********************************************************************************************************
* NETWORK ARGUMENT CHECK CONFIGURATION
*
* Note(s) : (1) Configure NET_ERR_CFG_ARG_CHK_EXT_EN to enable/disable the network protocol suite external
* argument check feature :
*
* (a) When ENABLED, ALL arguments received from any port interface provided by the developer
* or application are checked/validated.
*
* (b) When DISABLED, NO arguments received from any port interface provided by the developer
* or application are checked/validated.
*
* (2) Configure NET_ERR_CFG_ARG_CHK_DBG_EN to enable/disable the network protocol suite internal,
* debug argument check feature :
*
* (a) When ENABLED, internal arguments are checked/validated to debug the network protocol
* suite.
*
* (b) When DISABLED, NO internal arguments are checked/validated to debug the network protocol
* suite.
*********************************************************************************************************
*/
/* Configure external argument check feature ... */
/* ... (see Note #1) : */
#define NET_ERR_CFG_ARG_CHK_EXT_EN DEF_ENABLED
/* DEF_DISABLED Argument check DISABLED */
/* DEF_ENABLED Argument check ENABLED */
/* Configure internal argument check feature ... */
/* ... (see Note #2) : */
#define NET_ERR_CFG_ARG_CHK_DBG_EN DEF_DISABLED
/* DEF_DISABLED Argument check DISABLED */
/* DEF_ENABLED Argument check ENABLED */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK COUNTER MANAGEMENT CONFIGURATION
*
* Note(s) : (1) Configure NET_CTR_CFG_STAT_EN to enable/disable network protocol suite statistics counters.
*
* (2) Configure NET_CTR_CFG_ERR_EN to enable/disable network protocol suite error counters.
*********************************************************************************************************
*/
/* Configure statistics counter feature (see Note #1) : */
#define NET_CTR_CFG_STAT_EN DEF_ENABLED
/* DEF_DISABLED Stat counters DISABLED */
/* DEF_ENABLED Stat counters ENABLED */
/* Configure error counter feature (see Note #2) : */
#define NET_CTR_CFG_ERR_EN DEF_DISABLED
/* DEF_DISABLED Error counters DISABLED */
/* DEF_ENABLED Error counters ENABLED */
/*
*********************************************************************************************************
* NETWORK STATISTIC MANAGEMENT CONFIGURATION
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK TIMER MANAGEMENT CONFIGURATION
*
* Note(s) : (1) Configure NET_TMR_CFG_NBR_TMR with the desired number of network TIMER objects.
*
* Timers are required for :
*
* (a) ARP cache entries
* (b) IP fragment reassembly
* (c) ICMP low-network-resources monitor task
* (d) TCP state machine connections
*
* (2) Configure NET_TMR_CFG_TASK_FREQ to schedule the execution frequency of the network timer
* task -- how often NetTmr_TaskHandler() is scheduled to run per second as implemented in
* NetOS_Tmr_Task().
*
* (a) NET_TMR_CFG_TASK_FREQ MUST NOT be configured as a floating-point frequency.
*
* See also 'net_tmr.h NETWORK TIMER TASK TIME DEFINES Notes #1 & #2'
* & 'net_os.c NetOS_Tmr_Task() Notes #1 & #2'.
*********************************************************************************************************
*/
#define NET_TMR_CFG_NBR_TMR 30u /* Configure total number of TIMERs (see Note #1). */
#define NET_TMR_CFG_TASK_FREQ 10u /* Configure Timer Task frequency (see Note #2). */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK INTERFACE LAYER CONFIGURATION
*
* Note(s) : (1) Configure NET_IF_CFG_&&&_EN to enable/disable specific network interface(s).
*********************************************************************************************************
*/
#define NET_IF_CFG_MAX_NBR_IF 1u /* Configure maximum number of network interfaces. */
/* Configure specific interface(s) [see Note #1] : */
#define NET_IF_CFG_LOOPBACK_EN DEF_DISABLED
#define NET_IF_CFG_ETHER_EN DEF_ENABLED
/* Configure network interface address filter feature : */
#define NET_IF_CFG_ADDR_FLTR_EN DEF_ENABLED
/* DEF_DISABLED Addresses NOT filtered */
/* DEF_ENABLED Addresses filtered */
/* Configure network interface transmit suspend ... */
#define NET_IF_CFG_TX_SUSPEND_TIMEOUT_MS 1u /* ... timeout in integer milliseconds. */
/*
*********************************************************************************************************
* ADDRESS RESOLUTION PROTOCOL LAYER CONFIGURATION
*
* Note(s) : (1) Address Resolution Protocol ONLY required for some network interfaces (see 'net_arp.h
* Note #1').
*
* (2) See 'net_arp.h ARP HARDWARE & PROTOCOL DEFINES Note #1' for supported ARP hardware &
* protocol types.
*
* (3) Configure NET_ARP_CFG_ADDR_FLTR_EN to enable/disable the ARP address filtering feature
* to selectively filter & discard ALL misdirected or incorrectly received ARP messages.
*********************************************************************************************************
*/
/* Configure ARP types (see Note #2) : */
#define NET_ARP_CFG_HW_TYPE NET_ARP_HW_TYPE_ETHER
#define NET_ARP_CFG_PROTOCOL_TYPE NET_ARP_PROTOCOL_TYPE_IP_V4
#define NET_ARP_CFG_NBR_CACHE 3u /* Configure ARP cache size. */
/* Configure ARP address filter feature (see Note #3) : */
#define NET_ARP_CFG_ADDR_FLTR_EN DEF_ENABLED
/* DEF_DISABLED ARP addresses NOT filtered */
/* DEF_ENABLED ARP addresses filtered */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK MANAGER LAYER CONFIGURATION
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INTERNET PROTOCOL LAYER CONFIGURATION
*
* Note(s) : (1) Configure NET_IP_CFG_MULTICAST_SEL with the desired configuration for IP multicasting :
*
* NET_IP_MULTICAST_SEL_NONE NO multicasting
* NET_IP_MULTICAST_SEL_TX Transmit multicasting ONLY
* NET_IP_MULTICAST_SEL_TX_RX Transmit & receive multicasting, with IGMP support
*
* See also 'net_igmp.c Note #1'.
*********************************************************************************************************
*/
#define NET_IP_CFG_IF_MAX_NBR_ADDR 1u /* Configure maximum number of addresses per interface. */
/* Configure multicast support (see Note #1) : */
#define NET_IP_CFG_MULTICAST_SEL NET_IP_MULTICAST_SEL_NONE
/* NET_IP_MULTICAST_SEL_NONE NO multicasting */
/* NET_IP_MULTICAST_SEL_TX Transmit multicasting */
/* ONLY */
/* NET_IP_MULTICAST_SEL_TX_RX Transmit & receive */
/* multicasting */
/*
*********************************************************************************************************
* INTERNET CONTROL MESSAGE PROTOCOL LAYER CONFIGURATION
*********************************************************************************************************
*/
/* Configure ICMP Transmit Source Quench feature : */
#define NET_ICMP_CFG_TX_SRC_QUENCH_EN DEF_DISABLED
/* DEF_DISABLED ICMP Transmit Source Quench DISABLED */
/* DEF_ENABLED ICMP Transmit Source Quench ENABLED */
#define NET_ICMP_CFG_TX_SRC_QUENCH_NBR 5u /* Configure ICMP transmit source quench list size. */
/*
*********************************************************************************************************
* INTERNET GROUP MANAGEMENT PROTOCOL LAYER CONFIGURATION
*********************************************************************************************************
*/
#define NET_IGMP_CFG_MAX_NBR_HOST_GRP 2u /* Configure maximum number of IGMP host groups. */
/*$PAGE*/
/*
*********************************************************************************************************
* TRANSPORT LAYER CONFIGURATION
*********************************************************************************************************
*/
/* Configure Transport Layer Selection : */
#define NET_CFG_TRANSPORT_LAYER_SEL NET_TRANSPORT_LAYER_SEL_UDP_TCP
/* NET_TRANSPORT_LAYER_SEL_UDP UDP ONLY */
/* NET_TRANSPORT_LAYER_SEL_UDP_TCP UDP/TCP */
/*
*********************************************************************************************************
* USER DATAGRAM PROTOCOL LAYER CONFIGURATION
*
* Note(s) : (1) Configure NET_UDP_CFG_APP_API_SEL with the desired configuration for demultiplexing
* UDP datagrams to application connections :
*
* NET_UDP_APP_API_SEL_SOCK Demultiplex UDP datagrams to BSD sockets ONLY.
* NET_UDP_APP_API_SEL_APP Demultiplex UDP datagrams to application-specific
* connections ONLY.
* NET_UDP_APP_API_SEL_SOCK_APP Demultiplex UDP datagrams to BSD sockets first;
* if NO socket connection found to demultiplex
* a UDP datagram, demultiplex to application-
* specific connection.
*
* See also 'net_udp.c NetUDP_RxPktDemuxDatagram() Note #1'
* & 'net_udp.c NetUDP_RxPktDemuxAppData() Note #1'.
*
* (2) (a) RFC #1122, Section 4.1.3.4 states that "an application MAY optionally ... discard
* ... [or allow] ... received ... UDP datagrams without checksums".
*
* (b) Configure NET_UDP_CFG_RX_CHK_SUM_DISCARD_EN to enable/disable discarding of UDP
* datagrams received with NO computed check-sum :
*
* (1) When ENABLED, ALL UDP datagrams received without a check-sum are discarded.
*
* (2) When DISABLED, ALL UDP datagrams received without a check-sum are flagged so
* that application(s) may handle &/or discard.
*
* See also 'net_udp.c NetUDP_RxPktValidate() Note #4d3A'.
*
* (3) (a) RFC #1122, Section 4.1.3.4 states that "an application MAY optionally be able to
* control whether a UDP checksum will be generated".
*
* (b) Configure NET_UDP_CFG_TX_CHK_SUM_EN to enable/disable transmitting UDP datagrams
* with check-sums :
*
* (1) When ENABLED, ALL UDP datagrams are transmitted with a computed check-sum.
*
* (2) When DISABLED, ALL UDP datagrams are transmitted without a computed check-sum.
*
* See also 'net_udp.c NetUDP_TxPktPrepareHdr() Note #3b'.
*********************************************************************************************************
*/
/* Configure UDP Receive Demultiplex Selection ... */
/* ... (see Note #1) : */
#define NET_UDP_CFG_APP_API_SEL NET_UDP_APP_API_SEL_SOCK
/* Demultiplex & Receive via ... */
/* NET_UDP_APP_API_SEL_SOCK Sockets ONLY */
/* NET_UDP_APP_API_SEL_APP Application ONLY */
/* NET_UDP_APP_API_SEL_SOCK_APP First by Socket, */
/* Next by Application */
/* Configure UDP Receive Check-Sum Discard feature ... */
/* ... (see Note #2b) : */
#define NET_UDP_CFG_RX_CHK_SUM_DISCARD_EN DEF_DISABLED
/* DEF_DISABLED UDP Datagrams Received without ... */
/* Check-Sums Validated */
/* DEF_ENABLED UDP Datagrams Received without ... */
/* Check-Sums Discarded */
/* Configure UDP Transmit Check-Sum feature ... */
/* ... (see Note #3b) : */
#define NET_UDP_CFG_TX_CHK_SUM_EN DEF_ENABLED
/* DEF_DISABLED Transmit Check-Sums DISABLED */
/* DEF_ENABLED Transmit Check-Sums ENABLED */
/*$PAGE*/
/*
*********************************************************************************************************
* TRANSMISSION CONTROL PROTOCOL LAYER CONFIGURATION
*
* Note(s) : (1) (a) Configure NET_TCP_CFG_NBR_CONN with the desired number of TCP connection objects.
*
* (b) Since TCP requires network sockets (see 'net_tcp.h Note #2'), the configured number
* of sockets MUST be greater than or equal to the configured number of TCP connections.
*
* See also 'net_sock.h MODULE Note #1',
* 'net_tcp.h MODULE Note #1',
* & 'net_cfg_net.h NETWORK SOCKET LAYER CONFIGURATION Note #4'.
*
* (2) Stevens, TCP/IP Illustrated, Volume 1, 8th Printing, Section 20.4, Page 282 states that
* "4.2BSD defaulted the send and receive buffer" (i.e. socket buffer/TCP window) "to 2048
* bytes each. With 4.3BSD both were increased to 4096 bytes ... Other systems, such as
* ... 4.4BSD ... use larger default buffer sizes, such as 8192 or 16384 bytes.
*
* The common default of 4096 bytes ... is not optimal for Ethernet. An approximate 40%
* increase in throughput is seen by just increasing both buffers to 16384 bytes."
*
* (3) RFC #793, Section 3.3 'Sequence Numbers : Knowing When to Keep Quiet' states that
* "the Maximum Segment Lifetime (MSL) is ... to be 2 minutes ... [but] may be changed
* if experience indicates it is desirable to do so".
*
* See also 'net_tcp.h TCP CONNECTION TIMEOUT DEFINES Note #1'.
*
* (4) RFC #2581, Section 4.2 states that "an ACK ... MUST be generated within 500 ms of the
* arrival of the first unacknowledged packet".
*
* See also 'net_tcp.h TCP CONGESTION CONTROL DEFINES Note #6b'
* & 'net_tcp.c NetTCP_TxConnAck() Note #6a2'.
*
* (5) Configure timeout values in integer number of milliseconds. Timeout values may also
* be configured with network time constant, NET_TMR_TIME_INFINITE, to never timeout.
*********************************************************************************************************
*/
#define NET_TCP_CFG_NBR_CONN 10 /* Configure total number of TCP connections. */
/* Configure TCP connections' window sizes ... */
/* ... in integer number of octets (see Note #2) : */
#define NET_TCP_CFG_RX_WIN_SIZE_OCTET (3u * 1460u) /* Configure TCP connection receive window size. */
#define NET_TCP_CFG_TX_WIN_SIZE_OCTET (3u * 1460u) /* Configure TCP connection transmit window size. */
/* Configure TCP connections' default maximum ... */
/* ... segment lifetime timeout (MSL) value, ... */
#define NET_TCP_CFG_TIMEOUT_CONN_MAX_SEG_SEC 3u /* ... in integer seconds (see Note #3). */
/* Configure TCP acknowledgement delay ... */
#define NET_TCP_CFG_TIMEOUT_CONN_ACK_DLY_MS 500u /* ... in integer milliseconds (see Note #4). */
/* Configure TCP timeouts (see Note #5) : */
/* Configure TCP connection receive queue timeout. */
#define NET_TCP_CFG_TIMEOUT_CONN_RX_Q_MS NET_TMR_TIME_INFINITE
/* Configure TCP connection transmit queue timeout. */
#define NET_TCP_CFG_TIMEOUT_CONN_TX_Q_MS NET_TMR_TIME_INFINITE
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK SOCKET LAYER CONFIGURATION
*
* Note(s) : (1) Network Socket Layer NOT required for all application interfaces (see 'net_sock.h
* MODULE Note #1').
*
* (2) See 'net_sock.h NETWORK SOCKET FAMILY & PROTOCOL DEFINES Note #1' for supported
* Network Socket Family types.
*
* (3) Configure socket select maximum number of socket events/operations to wait on.
*
* See 'net_sock.c NetSock_Sel() Note #4b'
* & 'net_os.c NetOS_Sock_SelWait() Note #2b2'.
*
* (4) Configure timeout values in integer number of milliseconds. Timeout values may also
* be configured with network time constant, NET_TMR_TIME_INFINITE, to never timeout.
*********************************************************************************************************
*/
/* Configure socket family type (see Note #2) : */
#define NET_SOCK_CFG_FAMILY NET_SOCK_FAMILY_IP_V4
#define NET_SOCK_CFG_NBR_SOCK 10 /* Configure total number of sockets. */
/* Configure socket default blocking behavior : */
#define NET_SOCK_CFG_BLOCK_SEL NET_SOCK_BLOCK_SEL_BLOCK
/* NET_SOCK_BLOCK_SEL_DFLT / */
/* NET_SOCK_BLOCK_SEL_BLOCK Blocking ENABLED */
/* NET_SOCK_BLOCK_SEL_NO_BLOCK Blocking DISABLED */
/* Configure socket select functionality : */
#define NET_SOCK_CFG_SEL_EN DEF_DISABLED
/* DEF_DISABLED Socket select DISABLED */
/* DEF_ENABLED Socket select ENABLED */
/* Configure maximum number of socket select ... */
#define NET_SOCK_CFG_SEL_NBR_EVENTS_MAX 10u /* ... operations/events to wait on (see Note #3). */
/* Configure stream-type sockets' accept queue ... */
#define NET_SOCK_CFG_CONN_ACCEPT_Q_SIZE_MAX 5u /* ... maximum size. */
#define NET_SOCK_CFG_PORT_NBR_RANDOM_BASE 65000u /* Configure random ports' starting port number. */
/* Configure socket timeout values (see Note #4) : */
/* Configure socket receive queue timeout. */
#define NET_SOCK_CFG_TIMEOUT_RX_Q_MS NET_TMR_TIME_INFINITE
/* Configure socket connection request timeout. */
#define NET_SOCK_CFG_TIMEOUT_CONN_REQ_MS NET_TMR_TIME_INFINITE
/* Configure socket connection accept timeout. */
#define NET_SOCK_CFG_TIMEOUT_CONN_ACCEPT_MS NET_TMR_TIME_INFINITE
/* Configure socket connection close timeout. */
#define NET_SOCK_CFG_TIMEOUT_CONN_CLOSE_MS 10000u
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK SECURITY MANAGER CONFIGURATION
*
* Note(s) : (1) Configure NET_SECURE_CFG_EN to enable/disable network security management.
*
* (2) Configure NET_SECURE_CFG_FS_EN to enable/disable network security management file system
* functionality.
*
* (3) Configure NET_SECURE_CFG_WORD_SIZE for optimized word size for security port, if applicable.
*
* (4) (a) Configure NET_SECURE_CFG_CLIENT_DOWNGRADE_EN to enable/disable client downgrade option.
*
* If NET_SECURE_CFG_CLIENT_DOWNGRADE_EN is DEF_ENABLED, client applications will be
* allowed to connect on server that is using a SSL/TLS version older than
* NET_SECURE_CFG_VER.
*
* It is recommended to configure NET_SECURE_CFG_CLIENT_DOWNGRADE_EN to DEF_DISABLED.
* If a client is running SSL V3.0, he MIGHT NOT want to exchange secure information
* with a server running SSL V2.0 because there is important security leakage in
* that version of the protocol.
*
* (b) Configure NET_SECURE_CFG_SERVER_DOWNGRADE_EN to enable/disable server downgrade option.
*
* If NET_SECURE_CFG_SERVER_DOWNGRADE_EN is DEF_ENABLED, server applications will be
* able to accept connection requests coming from clients that are using a SSL/TLS
* version older than NET_SECURE_CFG_VER.
*
* It is recommended to configure NET_SECURE_CFG_CLIENT_DOWNGRADE_EN to DEF_ENABLED
* since the client is responsible of choosing a SSL/TLS protocol version that matches
* its security requirements.
*
* (5) The common name is chosen during the creation of the certificate (e.g. 'Micrium',
* 'Google', 'Paypal', etc.).
*
* (6) The public key is a part of the public key certificate. The length of the public
* key is chosen during the creation of the certificate.
*********************************************************************************************************
*/
/*$PAGE*/
/* Configure Network Security Manager (see Note #1) : */
#define NET_SECURE_CFG_EN DEF_DISABLED
/* DEF_DISABLED Network security manager DISABLED */
/* DEF_ENABLED Network security manager ENABLED */
/* Configure File System feature(s) [see Note #2] : */
#define NET_SECURE_CFG_FS_EN DEF_DISABLED
/* DEF_DISABLED File System feature(s) DISABLED */
/* DEF_ENABLED File System feature(s) ENABLED */
/* Configure secure protocol version : */
#define NET_SECURE_CFG_VER NET_SECURE_SSL_V3_0
/* NET_SECURE_SSL_V2_0 SSL V2.0 */
/* NET_SECURE_SSL_V3_0 SSL V3.0 */
/* NET_SECURE_TLS_V1_0 TLS V1.0 */
/* NET_SECURE_TLS_V1_1 TLS V1.1 */
/* NET_SECURE_TLS_V1_2 TLS V1.2 */
/* Configure network security word size (see Note #3) : */
#define NET_SECURE_CFG_WORD_SIZE CPU_WORD_SIZE_32
/* CPU_WORD_SIZE_08 8-bit word size */
/* CPU_WORD_SIZE_16 16-bit word size */
/* CPU_WORD_SIZE_32 32-bit word size */
/* CPU_WORD_SIZE_64 64-bit word size */
/* Configure client downgrade option (see Note #4a) : */
#define NET_SECURE_CFG_CLIENT_DOWNGRADE_EN DEF_DISABLED
/* DEF_DISABLED Client downgrade DISABLED */
/* DEF_ENABLED Client downgrade ENABLED */
/* Configure server downgrade option (see Note #4b) : */
#define NET_SECURE_CFG_SERVER_DOWNGRADE_EN DEF_ENABLED
/* DEF_DISABLED Server downgrade DISABLED */
/* DEF_ENABLED Server downgrade ENABLED */
#define NET_SECURE_CFG_MAX_NBR_SOCK 5u /* Configure maximum number of sockets to secure. */
/* Configure maximum number of certificate authorities */
#define NET_SECURE_CFG_MAX_NBR_CA 1u /* ... that can be installed. */
/* Configure maximum length (in octets) of ... */
#define NET_SECURE_CFG_MAX_KEY_LEN 1500u /* ... certificate authority, certificates & keys. */
/* Configure maximum length (in octets) of common name */
#define NET_SECURE_CFG_MAX_ISSUER_CN_LEN 20u /* ... (see Note #5). */
/* Configure maximum length (in octets) of public key */
#define NET_SECURE_CFG_MAX_PUBLIC_KEY_LEN 256u /* ... (see Note #6). */
/*$PAGE*/
/*
*********************************************************************************************************
* BSD 4.x LAYER CONFIGURATION
*
* Note(s) : (1) BSD 4.x Layer API NOT required for all applications (see 'net_bsd.h MODULE Note #1').
*********************************************************************************************************
*/
/* Configure BSD 4.x Layer API (see Note #1) : */
#define NET_BSD_CFG_API_EN DEF_ENABLED
/* DEF_DISABLED BSD 4.x Layer API DISABLED */
/* DEF_ENABLED BSD 4.x Layer API ENABLED */
/*
*********************************************************************************************************
* NETWORK APPLICATION PROGRAMMING INTERFACE (API) LAYER CONFIGURATION
*
* Note(s) : (1) Network Application Programming Interface (API) Layer NOT required for all applications
* (see 'net_app.h MODULE Note #1').
*********************************************************************************************************
*/
/* Configure Network API Layer (see Note #1) : */
#define NET_APP_CFG_API_EN DEF_ENABLED
/* DEF_DISABLED Network API Layer DISABLED */
/* DEF_ENABLED Network API Layer ENABLED */
/*$PAGE*/
/*
*********************************************************************************************************
* NETWORK CONNECTION MANAGEMENT CONFIGURATION
*
* Note(s) : (1) Network Connection Management NOT required for all application interfaces (see 'net_conn.h
* MODULE Note #1').
*
* (2) See 'net_def.h NETWORK CONNECTION MANAGEMENT DEFINES' for supported Family types.
*
* (3) The configured number of connections MUST be greater than the configured/required/expected
* number of application connections & transport layer connections.
*
* See also 'net_cfg_net.h NETWORK CONNECTION MANAGEMENT CONFIGURATION Note #4'.
*********************************************************************************************************
*/
/* Configure connection family type (see Note #2). */
#define NET_CONN_CFG_FAMILY NET_CONN_FAMILY_IP_V4_SOCK
#define NET_CONN_CFG_NBR_CONN 20 /* Configure total number of connections (see Note #3). */
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/Init/inthandler.h
|
/***********************************************************************/
/* */
/* FILE :inthandler.h */
/* DATE :Mon, Jun 28, 2010 */
/* DESCRIPTION :Interrupt Handler Declarations */
/* CPU TYPE :Other */
/* */
/* This file is generated by KPIT GNU Project Generator. */
/* */
/***********************************************************************/
#ifndef INTHANDLER_H
#define INTHANDLER_H
// Exception(Supervisor Instruction)
void INT_Excep_SuperVisorInst(void) __attribute__ ((interrupt));
// Exception(Undefined Instruction)
void INT_Excep_UndefinedInst(void) __attribute__ ((interrupt));
// Exception(Floating Point)
void INT_Excep_FloatingPoint(void) __attribute__ ((interrupt));
// NMI
void INT_NonMaskableInterrupt(void) __attribute__ ((interrupt));
// Dummy
void Dummy (void) __attribute__ ((interrupt));
// BRK
void INT_Excep_BRK(void) __attribute__ ((interrupt));
// vector 1 reserved
// vector 2 reserved
// vector 3 reserved
// vector 4 reserved
// vector 5 reserved
// vector 6 reserved
// vector 7 reserved
// vector 8 reserved
// vector 9 reserved
// vector 10 reserved
// vector 11 reserved
// vector 12 reserved
// vector 13 reserved
// vector 14 reserved
// vector 15 reserved
// BUSERR
void INT_Excep_BUSERR(void) __attribute__ ((interrupt));
// vector 17 reserved
// vector 18 reserved
// vector 19 reserved
// vector 20 reserved
// FCU_FCUERR
void INT_Excep_FCU_FCUERR(void) __attribute__ ((interrupt));
// vector 22 reserved
// FCU_FRDYI
void INT_Excep_FCU_FRDYI(void) __attribute__ ((interrupt));
// vector 24 reserved
// vector 25 reserved
// vector 26 reserved
// ICU_SWINT
void INT_Excep_ICU_SWINT(void) __attribute__ ((interrupt));
// CMTU0_CMT0
void INT_Excep_CMTU0_CMT0(void) __attribute__ ((interrupt));
// CMTU0_CMT1
void INT_Excep_CMTU0_CMT1(void) __attribute__ ((interrupt));
// CMTU1_CMT2
void INT_Excep_CMTU1_CMT2(void) __attribute__ ((interrupt));
// CMTU1_CMT3
void INT_Excep_CMTU1_CMT3(void) __attribute__ ((interrupt));
// Ether_EINT
void INT_Excep_Ether_EINT(void) __attribute__ ((interrupt));
// vector 33 reserved
// vector 34 reserved
// vector 35 reserved
// USB0_D0FIFO0
void INT_Excep_USB0_D0FIFO0(void) __attribute__ ((interrupt));
// USB0_D1FIFO0
void INT_Excep_USB0_D1FIFO0(void) __attribute__ ((interrupt));
// USB0_USBI0
void INT_Excep_USB0_USBI0(void) __attribute__ ((interrupt));
// vector 39 reserved
// USB1_D0FIFO1
void INT_Excep_USB1_D0FIFO1(void) __attribute__ ((interrupt));
// USB1_D1FIFO1
void INT_Excep_USB1_D1FIFO1(void) __attribute__ ((interrupt));
// USB1_USBI1
void INT_Excep_USB1_USBI1(void) __attribute__ ((interrupt));
// vector 43 reserved
// RSPI0_SPEI0
void INT_Excep_RSPI0_SPEI0(void) __attribute__ ((interrupt));
// RSPI0_SPRI0
void INT_Excep_RSPI0_SPRI0(void) __attribute__ ((interrupt));
// RSPI0_SPTI0
void INT_Excep_RSPI0_SPTI0(void) __attribute__ ((interrupt));
// RSPI0_SPII0
void INT_Excep_RSPI0_SPII0(void) __attribute__ ((interrupt));
// RSPI1_SPEI1
void INT_Excep_RSPI1_SPEI1(void) __attribute__ ((interrupt));
// RSPI1_SPRI1
void INT_Excep_RSPI1_SPRI1(void) __attribute__ ((interrupt));
// RSPI1_SPTI1
void INT_Excep_RSPI1_SPTI1(void) __attribute__ ((interrupt));
// RSPI1_SPII1
void INT_Excep_RSPI1_SPII1(void) __attribute__ ((interrupt));
// vector 52 reserved
// vector 53 reserved
// vector 54 reserved
// vector 55 reserved
// CAN0_ERS0
void INT_Excep_CAN0_ERS0(void) __attribute__ ((interrupt));
// CAN0_RXF0
void INT_Excep_CAN0_RXF0(void) __attribute__ ((interrupt));
// CAN0_TXF0
void INT_Excep_CAN0_TXF0(void) __attribute__ ((interrupt));
// CAN0_RXM0
void INT_Excep_CAN0_RXM0(void) __attribute__ ((interrupt));
// CAN0_TXM0
void INT_Excep_CAN0_TXM0(void) __attribute__ ((interrupt));
// vector 61 reserved
// RTC_PRD
void INT_Excep_RTC_PRD(void) __attribute__ ((interrupt));
// RTC_CUP
void INT_Excep_RTC_CUP(void) __attribute__ ((interrupt));
// IRQ0
void INT_Excep_IRQ0(void) __attribute__ ((interrupt));
// IRQ1
void INT_Excep_IRQ1(void) __attribute__ ((interrupt));
// IRQ2
void INT_Excep_IRQ2(void) __attribute__ ((interrupt));
// IRQ3
void INT_Excep_IRQ3(void) __attribute__ ((interrupt));
// IRQ4
void INT_Excep_IRQ4(void) __attribute__ ((interrupt));
// IRQ5
void INT_Excep_IRQ5(void) __attribute__ ((interrupt));
// IRQ6
void INT_Excep_IRQ6(void) __attribute__ ((interrupt));
// IRQ7
void INT_Excep_IRQ7(void) __attribute__ ((interrupt));
// IRQ8
void INT_Excep_IRQ8(void) __attribute__ ((interrupt));
// IRQ9
void INT_Excep_IRQ9(void) __attribute__ ((interrupt));
// IRQ10
void INT_Excep_IRQ10(void) __attribute__ ((interrupt));
// IRQ11
void INT_Excep_IRQ11(void) __attribute__ ((interrupt));
// IRQ12
void INT_Excep_IRQ12(void) __attribute__ ((interrupt));
// IRQ13
void INT_Excep_IRQ13(void) __attribute__ ((interrupt));
// IRQ14
void INT_Excep_IRQ14(void) __attribute__ ((interrupt));
// IRQ15
void INT_Excep_IRQ15(void) __attribute__ ((interrupt));
// vector 80 reserved
// vector 81 reserved
// vector 82 reserved
// vector 83 reserved
// vector 84 reserved
// vector 85 reserved
// vector 86 reserved
// vector 87 reserved
// vector 88 reserved
// vector 89 reserved
// USB_resume_USBR0
void INT_Excep_USB_resume_USBR0(void) __attribute__ ((interrupt));
// USB_resume_USBR1
void INT_Excep_USB_resume_USBR1(void) __attribute__ ((interrupt));
// RTC_ALM
void INT_Excep_RTC_ALM(void) __attribute__ ((interrupt));
// vector 93 reserved
// vector 94 reserved
// vector 95 reserved
// WDT_WOVI
void INT_Excep_WDT_WOVI(void) __attribute__ ((interrupt));
// vector 97 reserved
// AD0_ADI0
void INT_Excep_AD0_ADI0(void) __attribute__ ((interrupt));
// AD1_ADI1
void INT_Excep_AD1_ADI1(void) __attribute__ ((interrupt));
// vector 100 reserved
// vector 101 reserved
// S12AD_ADI12_0
void INT_Excep_S12AD_ADI12_0(void) __attribute__ ((interrupt));
// vector 103 reserved
// vector 104 reserved
// vector 105 reserved
// vector 106 reserved
// vector 107 reserved
// vector 108 reserved
// vector 109 reserved
// vector 110 reserved
// vector 111 reserved
// vector 112 reserved
// vector 113 reserved
// MTU0_TGIA0
void INT_Excep_MTU0_TGIA0(void) __attribute__ ((interrupt));
// MTU0_TGIB0
void INT_Excep_MTU0_TGIB0(void) __attribute__ ((interrupt));
// MTU0_TGIC0
void INT_Excep_MTU0_TGIC0(void) __attribute__ ((interrupt));
// MTU0_TGID0
void INT_Excep_MTU0_TGID0(void) __attribute__ ((interrupt));
// MTU0_TGIV0
void INT_Excep_MTU0_TGIV0(void) __attribute__ ((interrupt));
// MTU0_TGIE0
void INT_Excep_MTU0_TGIE0(void) __attribute__ ((interrupt));
// MTU0_TGIF0
void INT_Excep_MTU0_TGIF0(void) __attribute__ ((interrupt));
// MTU1_TGIA1
void INT_Excep_MTU1_TGIA1(void) __attribute__ ((interrupt));
// MTU1_TGIB1
void INT_Excep_MTU1_TGIB1(void) __attribute__ ((interrupt));
// MTU1_TGIV1
void INT_Excep_MTU1_TGIV1(void) __attribute__ ((interrupt));
// MTU1_TGIU1
void INT_Excep_MTU1_TGIU1(void) __attribute__ ((interrupt));
// MTU2_TGIA2
void INT_Excep_MTU2_TGIA2(void) __attribute__ ((interrupt));
// MTU2_TGIB2
void INT_Excep_MTU2_TGIB2(void) __attribute__ ((interrupt));
// MTU2_TGIV2
void INT_Excep_MTU2_TGIV2(void) __attribute__ ((interrupt));
// MTU2_TGIU2
void INT_Excep_MTU2_TGIU2(void) __attribute__ ((interrupt));
// MTU3_TGIA3
void INT_Excep_MTU3_TGIA3(void) __attribute__ ((interrupt));
// MTU3_TGIB3
void INT_Excep_MTU3_TGIB3(void) __attribute__ ((interrupt));
// MTU3_TGIC3
void INT_Excep_MTU3_TGIC3(void) __attribute__ ((interrupt));
// MTU3_TGID3
void INT_Excep_MTU3_TGID3(void) __attribute__ ((interrupt));
// MTU3_TGIV3
void INT_Excep_MTU3_TGIV3(void) __attribute__ ((interrupt));
// MTU4_TGIA4
void INT_Excep_MTU4_TGIA4(void) __attribute__ ((interrupt));
// MTU4_TGIB4
void INT_Excep_MTU4_TGIB4(void) __attribute__ ((interrupt));
// MTU4_TGIC4
void INT_Excep_MTU4_TGIC4(void) __attribute__ ((interrupt));
// MTU4_TGID4
void INT_Excep_MTU4_TGID4(void) __attribute__ ((interrupt));
// MTU4_TGIV4
void INT_Excep_MTU4_TGIV4(void) __attribute__ ((interrupt));
// MTU5_TGIU5
void INT_Excep_MTU5_TGIU5(void) __attribute__ ((interrupt));
// MTU5_TGIV5
void INT_Excep_MTU5_TGIV5(void) __attribute__ ((interrupt));
// MTU5_TGIW5
void INT_Excep_MTU5_TGIW5(void) __attribute__ ((interrupt));
// MTU6_TGIA6
void INT_Excep_MTU6_TGIA6(void) __attribute__ ((interrupt));
// MTU6_TGIB6
void INT_Excep_MTU6_TGIB6(void) __attribute__ ((interrupt));
// MTU6_TGIC6
void INT_Excep_MTU6_TGIC6(void) __attribute__ ((interrupt));
// MTU6_TGID6
void INT_Excep_MTU6_TGID6(void) __attribute__ ((interrupt));
// MTU6_TGIV6
void INT_Excep_MTU6_TGIV6(void) __attribute__ ((interrupt));
// MTU6_TGIE6
void INT_Excep_MTU6_TGIE6(void) __attribute__ ((interrupt));
// MTU6_TGIF6
void INT_Excep_MTU6_TGIF6(void) __attribute__ ((interrupt));
// MTU7_TGIA7
void INT_Excep_MTU7_TGIA7(void) __attribute__ ((interrupt));
// MTU7_TGIB7
void INT_Excep_MTU7_TGIB7(void) __attribute__ ((interrupt));
// MTU7_TGIV7
void INT_Excep_MTU7_TGIV7(void) __attribute__ ((interrupt));
// MTU7_TGIU7
void INT_Excep_MTU7_TGIU7(void) __attribute__ ((interrupt));
// MTU8_TGIA8
void INT_Excep_MTU8_TGIA8(void) __attribute__ ((interrupt));
// MTU8_TGIB8
void INT_Excep_MTU8_TGIB8(void) __attribute__ ((interrupt));
// MTU8_TGIV8
void INT_Excep_MTU8_TGIV8(void) __attribute__ ((interrupt));
// MTU8_TGIU8
void INT_Excep_MTU8_TGIU8(void) __attribute__ ((interrupt));
// MTU9_TGIA9
void INT_Excep_MTU9_TGIA9(void) __attribute__ ((interrupt));
// MTU9_TGIB9
void INT_Excep_MTU9_TGIB9(void) __attribute__ ((interrupt));
// MTU9_TGIC9
void INT_Excep_MTU9_TGIC9(void) __attribute__ ((interrupt));
// MTU9_TGID9
void INT_Excep_MTU9_TGID9(void) __attribute__ ((interrupt));
// MTU9_TGIV9
void INT_Excep_MTU9_TGIV9(void) __attribute__ ((interrupt));
// MTU10_TGIA10
void INT_Excep_MTU10_TGIA10(void) __attribute__ ((interrupt));
// MTU10_TGIB10
void INT_Excep_MTU10_TGIB10(void) __attribute__ ((interrupt));
// MTU10_TGIC10
void INT_Excep_MTU10_TGIC10(void) __attribute__ ((interrupt));
// MTU10_TGID10
void INT_Excep_MTU10_TGID10(void) __attribute__ ((interrupt));
// MTU10_TGIV10
void INT_Excep_MTU10_TGIV10(void) __attribute__ ((interrupt));
// MTU11_TGIU11
void INT_Excep_MTU11_TGIU11(void) __attribute__ ((interrupt));
// MTU11_TGIV11
void INT_Excep_MTU11_TGIV11(void) __attribute__ ((interrupt));
// MTU11_TGIW11
void INT_Excep_MTU11_TGIW11(void) __attribute__ ((interrupt));
// POE_OEI1
void INT_Excep_POE_OEI1(void) __attribute__ ((interrupt));
// POE_OEI2
void INT_Excep_POE_OEI2(void) __attribute__ ((interrupt));
// POE_OEI3
void INT_Excep_POE_OEI3(void) __attribute__ ((interrupt));
// POE_OEI4
void INT_Excep_POE_OEI4(void) __attribute__ ((interrupt));
// TMR0_CMI0A
void INT_Excep_TMR0_CMI0A(void) __attribute__ ((interrupt));
// TMR0_CMI0B
void INT_Excep_TMR0_CMI0B(void) __attribute__ ((interrupt));
// TMR0_OV0I
void INT_Excep_TMR0_OV0I(void) __attribute__ ((interrupt));
// TMR1_CMI1A
void INT_Excep_TMR1_CMI1A(void) __attribute__ ((interrupt));
// TMR1_CMI1B
void INT_Excep_TMR1_CMI1B(void) __attribute__ ((interrupt));
// TMR1_OV1I
void INT_Excep_TMR1_OV1I(void) __attribute__ ((interrupt));
// TMR2_CMI2A
void INT_Excep_TMR2_CMI2A(void) __attribute__ ((interrupt));
// TMR2_CMI2B
void INT_Excep_TMR2_CMI2B(void) __attribute__ ((interrupt));
// TMR2_OV2I
void INT_Excep_TMR2_OV2I(void) __attribute__ ((interrupt));
// TMR3_CMI3A
void INT_Excep_TMR3_CMI3A(void) __attribute__ ((interrupt));
// TMR3_CMI3B
void INT_Excep_TMR3_CMI3B(void) __attribute__ ((interrupt));
// TMR3_OV3I
void INT_Excep_TMR3_OV3I(void) __attribute__ ((interrupt));
// vector 186 reserved
// vector 187 reserved
// vector 188 reserved
// vector 189 reserved
// vector 190 reserved
// vector 191 reserved
// vector 192 reserved
// vector 193 reserved
// vector 194 reserved
// vector 195 reserved
// vector 196 reserved
// vector 197 reserved
// DMACA_DMAC0I
void INT_Excep_DMACA_DMAC0I(void) __attribute__ ((interrupt));
// DMACA_DMAC1I
void INT_Excep_DMACA_DMAC1I(void) __attribute__ ((interrupt));
// DMACA_DMAC2I
void INT_Excep_DMACA_DMAC2I(void) __attribute__ ((interrupt));
// DMACA_DMAC3I
void INT_Excep_DMACA_DMAC3I(void) __attribute__ ((interrupt));
// EXDMAC_EXDMAC0I
void INT_Excep_EXDMAC_EXDMAC0I(void) __attribute__ ((interrupt));
// EXDMAC_EXDMAC1I
void INT_Excep_EXDMAC_EXDMAC1I(void) __attribute__ ((interrupt));
// vector 204 reserved
// vector 205 reserved
// vector 206 reserved
// vector 207 reserved
// vector 208 reserved
// vector 209 reserved
// vector 210 reserved
// vector 211 reserved
// vector 212 reserved
// vector 213 reserved
// SCI0_ERI0
void INT_Excep_SCI0_ERI0(void) __attribute__ ((interrupt));
// SCI0_RXI0
void INT_Excep_SCI0_RXI0(void) __attribute__ ((interrupt));
// SCI0_TXI0
void INT_Excep_SCI0_TXI0(void) __attribute__ ((interrupt));
// SCI0_TEI0
void INT_Excep_SCI0_TEI0(void) __attribute__ ((interrupt));
// SCI1_ERI1
void INT_Excep_SCI1_ERI1(void) __attribute__ ((interrupt));
// SCI1_RXI1
void INT_Excep_SCI1_RXI1(void) __attribute__ ((interrupt));
// SCI1_TXI1
void INT_Excep_SCI1_TXI1(void) __attribute__ ((interrupt));
// SCI1_TEI1
void INT_Excep_SCI1_TEI1(void) __attribute__ ((interrupt));
// SCI2_ERI2
void INT_Excep_SCI2_ERI2(void) __attribute__ ((interrupt));
// SCI2_RXI2
void INT_Excep_SCI2_RXI2(void) __attribute__ ((interrupt));
// SCI2_TXI2
void INT_Excep_SCI2_TXI2(void) __attribute__ ((interrupt));
// SCI2_TEI2
void INT_Excep_SCI2_TEI2(void) __attribute__ ((interrupt));
// SCI3_ERI3
void INT_Excep_SCI3_ERI3(void) __attribute__ ((interrupt));
// SCI3_RXI3
void INT_Excep_SCI3_RXI3(void) __attribute__ ((interrupt));
// SCI3_TXI3
void INT_Excep_SCI3_TXI3(void) __attribute__ ((interrupt));
// SCI3_TEI3
void INT_Excep_SCI3_TEI3(void) __attribute__ ((interrupt));
// vector 230 reserved
// vector 231 reserved
// vector 232 reserved
// vector 233 reserved
// SCI5_ERI5
void INT_Excep_SCI5_ERI5(void) __attribute__ ((interrupt));
// SCI5_RXI5
void INT_Excep_SCI5_RXI5(void) __attribute__ ((interrupt));
// SCI5_TXI5
void INT_Excep_SCI5_TXI5(void) __attribute__ ((interrupt));
// SCI5_TEI5
void INT_Excep_SCI5_TEI5(void) __attribute__ ((interrupt));
// SCI6_ERI6
void INT_Excep_SCI6_ERI6(void) __attribute__ ((interrupt));
// SCI6_RXI6
void INT_Excep_SCI6_RXI6(void) __attribute__ ((interrupt));
// SCI6_TXI6
void INT_Excep_SCI6_TXI6(void) __attribute__ ((interrupt));
// SCI6_TEI6
void INT_Excep_SCI6_TEI6(void) __attribute__ ((interrupt));
// vector 242 reserved
// vector 243 reserved
// vector 244 reserved
// vector 245 reserved
// RIIC0_ICEEI0
void INT_Excep_RIIC0_ICEEI0(void) __attribute__ ((interrupt));
// RIIC0_ICRXI0
void INT_Excep_RIIC0_ICRXI0(void) __attribute__ ((interrupt));
// RIIC0_ICTXI0
void INT_Excep_RIIC0_ICTXI0(void) __attribute__ ((interrupt));
// RIIC0_ICTEI0
void INT_Excep_RIIC0_ICTEI0(void) __attribute__ ((interrupt));
// RIIC1_EEI1
void INT_Excep_RIIC1_ICEEI1(void) __attribute__ ((interrupt));
// RIIC1_RXI1
void INT_Excep_RIIC1_ICRXI1(void) __attribute__ ((interrupt));
// RIIC1_TXI1
void INT_Excep_RIIC1_ICTXI1(void) __attribute__ ((interrupt));
// RIIC1_TEI1
void INT_Excep_RIIC1_ICTEI1(void) __attribute__ ((interrupt));
// vector 254 reserved
// vector 255 reserved
//;<<VECTOR DATA START (POWER ON RESET)>>
//;Power On Reset PC
extern void PowerON_Reset_PC(void) __attribute__ ((interrupt));
//;<<VECTOR DATA END (POWER ON RESET)>>
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/app_cloud.c
|
/*
*********************************************************************************************************
* Exosite
* Exosite Device Cloud
*
* (c) Copyright 2011, Exosite
* All Rights Reserved
*
*
* File : APP_CLOUD.C
* By : CSR
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#include "iodefine.h"
/*
*********************************************************************************************************
* LOCAL ENUMERATIONS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_TCB CloudData_TaskTCB;
static CPU_STK CloudData_TaskStk[CLOUD_DATA_TASK_STK_SIZE]; /* Stack for cloud data task. */
static CPU_BOOLEAN DisableCloudStatus = 0;
enum STATUS_MESSAGES
{
MSG_ERROR,
MSG_CONNECTED,
MSG_UNAVAILABLE,
MSG_BLANK,
MSG_END
};
CPU_CHAR showMAC[18];
const CPU_CHAR msg_status[MSG_END][19] = { "Cloud: Error\0",
"Cloud: Connected\0",
"Cloud: Unavailable\0",
" \0"};
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
extern volatile CPU_INT08U AppCloudControlLedOn;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void CloudData_Task (void *p_arg); /* Cloud data task. */
static void UI_Update (CPU_CHAR message); /* Local function for LCD updates */
CPU_BOOLEAN Exosite_Init (CPU_CHAR *pVen, CPU_CHAR *pOS, CPU_CHAR *pVer, NET_IF_NBR if_nbr);
CPU_BOOLEAN Exosite_Reinit (void);
CPU_SIZE_T Exosite_Read (CPU_CHAR *pkey, CPU_CHAR *pbuf, CPU_SIZE_T buflen);
CPU_BOOLEAN Exosite_Write (CPU_CHAR *pkey, CPU_CHAR *pval);
CPU_BOOLEAN Exosite_Write_Batch (CPU_CHAR **pkeys, CPU_CHAR **pvalues, CPU_SIZE_T count);
CPU_BOOLEAN Exosite_GetMAC (CPU_CHAR * pMAC);
/*
*********************************************************************************************************
* AppCloud_Init()
*
* Description : Initialize cloud connectivity and keep synchronized
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void AppCloud_Init (CPU_BOOLEAN disableStatus)
{
OS_ERR err;
if (disableStatus)
DisableCloudStatus = 1;
OSTaskCreate((OS_TCB *)&CloudData_TaskTCB, /* Create cloud data reporting task. */
(CPU_CHAR *)"Cloud Data Task",
(OS_TASK_PTR ) CloudData_Task,
(void *) 0,
(OS_PRIO ) CLOUD_DATA_TASK_PRIO,
(CPU_STK *)&CloudData_TaskStk[0],
(CPU_STK_SIZE) CLOUD_DATA_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) CLOUD_DATA_TASK_STK_SIZE,
(OS_MSG_QTY ) 2u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
}
/*
*********************************************************************************************************
* CloudData_Task()
*
* Description : Sends sensor data to the cloud
*
* Argument(s) : p_arg Argument passed to 'CloudData_Task()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Caller(s) : This is a task.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void CloudData_Task (void *p_arg)
{
OS_ERR err;
CPU_CHAR *keys[1];
CPU_CHAR *values[1];
CPU_CHAR strping[4];
CPU_CHAR ping = 0;
CPU_CHAR ledctrl;
CPU_CHAR read_count = 0;
CPU_BOOLEAN cloud_available;
(void)p_arg;
keys[0] = "ping";
values[0] = strping;
// OS Name = "Micrium-Ex6" <- MAX Length = 24
// OS Ver = "3.01.2" <- MAX Length = 8
// Use network interface '1' MAC address
cloud_available = Exosite_Init("renesas", "Micrium-Ex6", "3.01.2", (NET_IF_NBR)1);
Str_Copy(showMAC, "MAC: ");
Exosite_GetMAC(&showMAC[5]);
while (DEF_TRUE)
{
if (DEF_TRUE != cloud_available)
{
UI_Update(MSG_UNAVAILABLE);
// Sleep 20 seconds
OSTimeDlyHMSM((CPU_INT16U) 0u,
(CPU_INT16U) 0u,
(CPU_INT16U) 20u,
(CPU_INT32U) 0u,
(OS_OPT ) OS_OPT_TIME_HMSM_NON_STRICT,
(OS_ERR *)&err);
// Retry cloud activation until successful
cloud_available = Exosite_Reinit();
}
else
{
if (read_count++ > 10) {
read_count = 0;
// Create string from ping value
Str_FmtNbr_Int32U(ping++,
3u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NULL,
DEF_NO,
DEF_YES,
&strping[0]);
if (DEF_TRUE != Exosite_Write_Batch(keys, values, 3))
{
UI_Update(MSG_ERROR);
}
else
{
UI_Update(MSG_CONNECTED);
}
}
if (1 == Exosite_Read("led_ctrl", &ledctrl, 1))
{
UI_Update(MSG_CONNECTED);
if ('0' == ledctrl)
{
AppCloudControlLedOn = 0;
}
if ('1' == ledctrl)
{
AppCloudControlLedOn = 1;
}
} else UI_Update(MSG_ERROR);
// Sleep 2 seconds
OSTimeDlyHMSM((CPU_INT16U) 0u,
(CPU_INT16U) 0u,
(CPU_INT16U) 2u,
(CPU_INT32U) 0u,
(OS_OPT ) OS_OPT_TIME_HMSM_NON_STRICT,
(OS_ERR *)&err);
}
}
}
/*
*********************************************************************************************************
* UI_Update()
*
* Description : Updates LCD with Cloud status messages
*
* Argument(s) : message Index into const message array.
*
* Return(s) : none.
*
* Caller(s) : CloudData_Task
*
* Note(s) : none.
*********************************************************************************************************
*/
static void UI_Update (CPU_CHAR message)
{
static CPU_CHAR display_status = 0;
if(!DisableCloudStatus)
{
if (!PORT4.PORT.BIT.B0 || //check if any switches are pressed
!PORT4.PORT.BIT.B1 ||
!PORT4.PORT.BIT.B2) {
display_status ^= 1;
if (!display_status) BSP_GraphLCD_String(3, msg_status[MSG_BLANK]); //only clear once on button press in case others want to use line 3
}
} else {
if (!PORT4.PORT.BIT.B0 && //check if any switches are pressed
!PORT4.PORT.BIT.B1 &&
!PORT4.PORT.BIT.B2) {
display_status =1;
if (!display_status) BSP_GraphLCD_String(3, msg_status[MSG_BLANK]); //only clear once on button press in case others want to use line 3
} else
display_status = 0;
}
if (display_status) {
BSP_GraphLCD_String(3, msg_status[MSG_BLANK]);
BSP_GraphLCD_String(4, msg_status[MSG_BLANK]);
BSP_GraphLCD_String(3, msg_status[message]);
BSP_GraphLCD_String(4, showMAC);
}
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib-Ex6/app_cfg.h
|
/*
*********************************************************************************************************
* uC/OS-III
* APPLICATION CONFIGURATION
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP_CFG.H
* By : FGK
*********************************************************************************************************
*/
#ifndef __APP_CFG_H__
#define __APP_CFG_H__
/*
*********************************************************************************************************
* ADDITIONAL uC/MODULE ENABLES
*********************************************************************************************************
*/
#define APP_CFG_TCPIP_MODULE_EN DEF_ENABLED /* DEF_ENABLED = Present, DEF_DISABLED = Not Present */
#define APP_CFG_DHCPc_MODULE_EN DEF_ENABLED
#define APP_CFG_TFTPs_MODULE_EN DEF_ENABLED
#define APP_CFG_FS_EN DEF_ENABLED
#define APP_CFG_AUDIO_EN DEF_ENABLED
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
#if (APP_CFG_DHCPc_MODULE_EN > 0u)
#include <dhcp-c_cfg.h>
#endif
#if (APP_CFG_TFTPs_MODULE_EN > 0u)
#include <tftp-s_cfg.h>
#endif
#endif
/*
*********************************************************************************************************
* TASK PRIORITIES
*********************************************************************************************************
*/
#define CLK_OS_CFG_TASK_PRIO 2u
#define APP_TASK_START_PRIO 4u
#define AUDIO_UI_TASK_PRIO 6u
#define AUDIO_MGR_TASK_PRIO 6u
#define NET_OS_CFG_TMR_TASK_PRIO 8u
#define NET_OS_CFG_IF_TX_DEALLOC_TASK_PRIO 7u
#define NET_OS_CFG_IF_LOOPBACK_TASK_PRIO 6u
#define NET_OS_CFG_IF_RX_TASK_PRIO 9u
#define CLOUD_DATA_TASK_PRIO 11u
/*
*********************************************************************************************************
* TASK STACK SIZES
*********************************************************************************************************
*/
#define CLK_OS_CFG_TASK_STK_SIZE 256u
#define APP_TASK_START_STK_SIZE 384u
#define AUDIO_UI_TASK_STK_SIZE 768u
#define AUDIO_MGR_TASK_STK_SIZE 640u
#define CLOUD_DATA_TASK_STK_SIZE 512u
#define NET_OS_CFG_TMR_TASK_STK_SIZE 768u
#define NET_OS_CFG_IF_TX_DEALLOC_TASK_STK_SIZE 512u
#define NET_OS_CFG_IF_LOOPBACK_TASK_STK_SIZE 512u
#define NET_OS_CFG_IF_RX_TASK_STK_SIZE 1280u
/*
*********************************************************************************************************
* uC/FS CONFIGURATION
*********************************************************************************************************
*/
#define APP_CFG_FS_SD_EN DEF_ENABLED
#define APP_CFG_FS_DEV_CNT 2u
#define APP_CFG_FS_VOL_CNT 2u
#define APP_CFG_FS_FILE_CNT 4u
#define APP_CFG_FS_DIR_CNT 1u
#define APP_CFG_FS_BUF_CNT (2u * APP_CFG_FS_VOL_CNT)
#define APP_CFG_FS_DEV_DRV_CNT 2u
#define APP_CFG_FS_MAX_SEC_SIZE 512u
#define APP_TRACE_DBG(x)
/*
*********************************************************************************************************
* uC/TCP-IP v2.0
*********************************************************************************************************
*/
#define NET_OS_CFG_IF_LOOPBACK_Q_SIZE 5u
#define NET_OS_CFG_IF_RX_Q_SIZE 14u
#define NET_OS_CFG_IF_TX_DEALLOC_Q_SIZE 10u
/*
*********************************************************************************************************
* uC/DHCPc v2.0
*********************************************************************************************************
*/
#define APP_CFG_DHCP_NBR_IF_CFGD 1u
/*
*********************************************************************************************************
* uC/LIB CONFIGURATION
*********************************************************************************************************
*/
#define LIB_MEM_CFG_OPTIMIZE_ASM_EN DEF_DISABLED
#define LIB_MEM_CFG_ARG_CHK_EXT_EN DEF_ENABLED
#define LIB_MEM_CFG_ALLOC_EN DEF_ENABLED
#if (APP_CFG_AUDIO_EN > 0u)
#define LIB_MEM_CFG_HEAP_SIZE (36416L + AUDIO_CFG_BUF_NBR * (AUDIO_CFG_BUF_SIZE + 24))
#else
#define LIB_MEM_CFG_HEAP_SIZE (36416L)
#endif
/*
*********************************************************************************************************
* uC/APPs FS
*********************************************************************************************************
*/
#define APPS_FS_CFG_MAX_FILE_NAME_LEN 20u
#define APPS_FS_CFG_NBR_FILES 3u
#define APPS_FS_CFG_NBR_DIRS 1u
/*
*********************************************************************************************************
* uC/Audio
*********************************************************************************************************
*/
#define AUDIO_CFG_BUF_NBR 26u
#define AUDIO_CFG_BUF_SIZE 512u
#define AUDIO_CFG_BUF_TH 32u
/*
*********************************************************************************************************
* BSP Serial CONFIGURATION
*********************************************************************************************************
*/
#define BSP_CFG_SER_COMM_SEL 2u
#define BSP_CFG_SER_ALT_SEL
#define BSP_CFG_SER_BAUDRATE 115200u
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/probe_com_cfg.h
|
/*
*********************************************************************************************************
* uC/Probe Communication
*
* (c) Copyright 2007-2008; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* COMMUNICATION: CONFIGURATION
*
* Filename : probe_com_cfg.h
* Version : V2.30
* Programmer(s) : BAN
*********************************************************************************************************
* Note(s) : (1) This file contains configuration constants for uC/Probe Communication Modules.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* COMMUNICATION METHOD CONFIGURATION
*********************************************************************************************************
*/
#define PROBE_COM_CFG_RS232_EN DEF_ENABLED /* Configure RS-232 communication availability. */
#define PROBE_COM_CFG_TCPIP_EN DEF_ENABLED /* Configure TCP/IP communication availability. */
#define PROBE_COM_CFG_USB_EN DEF_DISABLED /* Configure USB communication availability. */
/*
*********************************************************************************************************
* GENERAL COMMUNICATION CONFIGURATION
*
* Note(s) : (1) Configure PROBE_COM_CFG_RX_MAX_SIZE & PROBE_COM_CFG_TX_MAX_SIZE to the maximum receive
* & transmit packet sizes, respectively. Larger maximum packet sizes will result in more
* efficient communication with better throughput. The largest receive & transmit packets
* will be of comparable size, typically.
*
* (2) Configure PROBE_COM_CFG_WR_REQ_EN to enable/disable write request availability. If
* disabled, code to handle write requests (which allowing the Windows application to
* write target memory locations) will not be included.
*
* (3) Configure PROBE_COM_CFG_STR_REQ_EN to enable/disable string request availability. If
* disabled, code to handle string requests will not be included, and the string read/write
* interface functions will not be available.
*
* (a) Configure PROBE_COM_CFG_STR_IN_BUF_SIZE to the length of the string input buffer, in
* bytes.
*
* (b) Configure PROBE_COM_CFG_STR_OUT_BUF_SIZE to the length of the string output buffer,
* in bytes.
*
* (4) Configure PROBE_COM_CFG_TERMINAL_REQ_EN to enable/disable terminal request availability.
* If disabled, code to handle terminal requests will not be compiled, and the terminal
* interface functions will not be available.
*
* (5) Configure PROBE_COM_CFG_STAT_EN to enable disable statistics/counters.
*********************************************************************************************************
*/
#define PROBE_COM_CFG_RX_MAX_SIZE 256 /* Configure maximum receive packet size (see Note #1).*/
#define PROBE_COM_CFG_TX_MAX_SIZE 256 /* Configure maximum transmit packet size (see Note #1).*/
#define PROBE_COM_CFG_WR_REQ_EN DEF_ENABLED /* Configure write request availability (see Note #2). */
#define PROBE_COM_CFG_STR_REQ_EN DEF_ENABLED /* Configure string request availability (see Note #3). */
#define PROBE_COM_CFG_STR_IN_BUF_SIZE 128 /* Configure size of string input buf (see Note #3a).*/
#define PROBE_COM_CFG_STR_OUT_BUF_SIZE 2048 /* Configure size of string output buf (see Note #3b).*/
#define PROBE_COM_CFG_TERMINAL_REQ_EN DEF_DISABLED /* Configure terminal request availability ... */
/* ... (see Note #4). */
#define PROBE_COM_CFG_STAT_EN DEF_ENABLED /* Configure statistics/counters (see Note #5). */
/*
*********************************************************************************************************
* RS-232 COMMUNICATION CONFIGURATION
*
* Note(s) : (1) Configure PROBE_RS232_CFG_RX_BUF_SIZE & PROBE_RS232_CFG_TX_BUF_SIZE to the receive &
* transmit buffer sizes, respectively. These are, effectively, the sizes of the maximum
* receivable & transmittable packets, so should generally be configured to
* PROBE_COM_CFG_RX_MAX_SIZE & PROBE_COM_CFG_TX_MAX_SIZE, respectively.
*
* (2) Configure PROBE_RS232_CFG_PARSE_TASK_EN to enable/disable parsing of received packets at
* task level. If enabled, a task will be created to parse received packets. If disabled,
* packets will be parsed at interrupt-level.
*
* (a) Configure PROBE_RS232_CFG_TASK_PRIO to the priority of the parse task.
*
* (b) Configure PROBE_RS232_CFG_TASK_STK_SIZE to the stack size of the parse task.
*
* (3) Configure PROBE_RS232_CFG_COMM_SEL to the UART or serial communication interface selected.
*********************************************************************************************************
*/
#define PROBE_RS232_CFG_RX_BUF_SIZE PROBE_COM_CFG_RX_MAX_SIZE /* Configure receive buffer size (see Note #1). */
#define PROBE_RS232_CFG_TX_BUF_SIZE PROBE_COM_CFG_TX_MAX_SIZE /* Configure transmit buffer size (see Note #1). */
#define PROBE_RS232_CFG_PARSE_TASK_EN DEF_DISABLED /* Configure parse task presence (see Note #2). */
#define PROBE_RS232_CFG_TASK_PRIO 12 /* Configure parse task priority (see Note #2a). */
#define PROBE_RS232_CFG_TASK_STK_SIZE 512 /* Configure parse task stack size (see Note #2b). */
#define PROBE_RS232_UART_0 1
#define PROBE_RS232_UART_1 2
#define PROBE_RS232_UART_2 3
#define PROBE_RS232_UART_3 4
#define PROBE_RS232_UART_4 5
#define PROBE_RS232_UART_5 6
#define PROBE_RS232_UART_6 7
#define PROBE_RS232_UART_7 8
#define PROBE_RS232_UART_8 9
#define PROBE_RS232_UART_9 10
#define PROBE_RS232_UART_DBG 63
#define PROBE_RS232_CFG_COMM_SEL PROBE_RS232_UART_2 /* Configure UART selection (see Note #3). */
#define PROBE_CFG_RS232_UART_ALT DEF_ENABLED
/*
*********************************************************************************************************
* TCP/IP COMMUNICATION CONFIGURATION
*
* Note(s) : (1) Configure PROBE_TCPIP_CFG_RX_BUF_SIZE & PROBE_TCPIP_CFG_TX_BUF_SIZE to the receive &
* transmit buffer sizes, respectively. These are, effectively, the sizes of the maximum
* receivable & transmittable packets, so should generally be configured to
* PROBE_COM_CFG_RX_MAX_SIZE & PROBE_COM_CFG_TX_MAX_SIZE, respectively.
*
* (2) (a) Configure PROBE_TCPIP_CFG_TASK_PRIO to the priority of the server task.
*
* (b) Configure PROBE_TCPIP_CFG_TASK_STK_SIZE to the stack size of the server task.
*
* (3) Configure PROBE_TCPIP_CFG_PORT to the port on which the server listens for packets.
*********************************************************************************************************
*/
#define PROBE_TCPIP_CFG_RX_BUF_SIZE PROBE_COM_CFG_RX_MAX_SIZE /* Configure receive buffer size (see Note #1). */
#define PROBE_TCPIP_CFG_TX_BUF_SIZE PROBE_COM_CFG_TX_MAX_SIZE /* Configure transmit buffer size (see Note #1). */
#define PROBE_TCPIP_CFG_TASK_PRIO 13 /* Configure parse task priority (see Note #2a). */
#define PROBE_TCPIP_CFG_TASK_STK_SIZE 768 /* Configure parse task stack size (see Note #2b). */
#define PROBE_TCPIP_CFG_PORT 9930 /* Configure listening port of server (see Note #3). */
/*
*********************************************************************************************************
* USB COMMUNICATION CONFIGURATION
*
* Note(s) : (1) Configure PROBE_USB_CFG_RX_BUF_SIZE & PROBE_USB_CFG_TX_BUF_SIZE to the receive &
* transmit buffer sizes, respectively. These are, effectively, the sizes of the maximum
* receivable & transmittable packets, so should generally be configured to
* PROBE_COM_CFG_RX_MAX_SIZE & PROBE_COM_CFG_TX_MAX_SIZE, respectively.
*
* (2) (a) Configure PROBE_USB_CFG_TASK_PRIO to the priority of the server task.
*
* (b) Configure PROBE_TCPIP_CFG_TASK_STK_SIZE to the stack size of the server task.
*
* (3) Configure PROBE_TCPIP_CFG_PORT to the port on which the server listens for packets.
*********************************************************************************************************
*/
#define PROBE_USB_CFG_RX_BUF_SIZE PROBE_COM_CFG_RX_MAX_SIZE /* (a) Set Rx buffer size. */
#define PROBE_USB_CFG_TX_BUF_SIZE PROBE_COM_CFG_TX_MAX_SIZE /* (b) Set Tx buffer size. */
#define PROBE_USB_CFG_TASK_PRIO 14 /* (c) Set task priority. */
#define PROBE_USB_CFG_TASK_STK_SIZE 512 /* (d) Set task stack size. */
#define PROBE_USB_CFG_INIT_STACK DEF_TRUE /* (e) The USB comm module will init stack. */
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/app_audio.c
|
<filename>uCOS-III-Ex6/app_audio.c
/*
*********************************************************************************************************
* uC/Audio Player
* The Real-Time Kernel
*
* (c) Copyright 2011, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP_AUDIO.C
* By : FGK
* Version : V1.04
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#include <audio.h>
#include "iodefine.h"
/*
*********************************************************************************************************
* LOCAL ENUMERATIONS
*********************************************************************************************************
*/
typedef enum ui_state { /* --------------- USER INTERFACE STATES ------------- */
PLAYER_HELP = 0,
PLAYER_IP,
#if (AUDIO_CFG_SSM2377_EN > 0u)
PLAYER_GAIN,
#endif
SD_WAIT,
SD_OPEN,
SD_GETFILES,
UI_UPDATE,
UI_WAIT_ACTION,
PLAYLIST_PREV,
PLAYLIST_SELECT,
PLAYLIST_NEXT,
PLAYBACK_SELECT_NEXT,
PLAYBACK_START,
PLAYBACK_PAUSE,
PLAYBACK_STOP_START,
PLAYBACK_PLAY
} UI_STATE;
typedef enum msg_id {
MSG_START = 1,
MSG_PAUSE,
MSG_STOP
} MSG_ID;
/*
*********************************************************************************************************
* PLAYLIST DEFINES
*********************************************************************************************************
*/
#define APP_SONG_CACHE_NBR 5u
#define APP_SONG_NAME_SIZE_MAX 48u
#define APP_SONG_NAME_SIZE_MIN 4u
#define APP_USER_IF_FS_RETRIES_MAX 3u
#define APP_AUDIO_FS_VOL "sd:0:"
#define APP_AUDIO_FS_DEV "sd:0:"
#define APP_AUDIO_FS_FOLDER "\\Music\\"
/*
*********************************************************************************************************
* PUSH BUTTON MACRO'S
*********************************************************************************************************
*/
#define SWITCH1() (!(PORT4.PORT.BIT.B0))
#define SWITCH2() (!(PORT4.PORT.BIT.B1))
#define SWITCH3() (!(PORT4.PORT.BIT.B2))
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef struct audio_dev {
FS_FILE *FilePtr;
CPU_BOOLEAN Valid;
CPU_INT32U SampleRate;
} AUDIO_DEV;
typedef struct audio_info {
CPU_CHAR Name[APP_SONG_NAME_SIZE_MAX + 1];
CPU_BOOLEAN Valid;
CPU_INT16U NbrCh;
CPU_INT32U SamplesPerSec;
CPU_INT32U AvgBytesPerSec;
CPU_INT16U BitsPerSample;
CPU_INT32U TimeLen;
} AUDIO_INFO;
typedef struct audio_mgr_msg {
MSG_ID ID;
CPU_INT16U SongIx;
} AUDIO_MGR_MSG;
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_TCB AudioUI_TCB;
static CPU_STK AudioUI_TaskStk[AUDIO_UI_TASK_STK_SIZE];
static OS_TCB AudioMgr_TCB;
static CPU_STK AudioMgr_TaskStk[AUDIO_MGR_TASK_STK_SIZE];
static OS_SEM AudioMgr_Sem;
static AUDIO_MGR_MSG AudioMgr_MsgStart;
static AUDIO_MGR_MSG AudioMgr_MsgStop;
static CPU_BOOLEAN Audio_Playback;
static CPU_BOOLEAN Audio_Paused;
static AUDIO_INFO AudioSongInfoCache[APP_SONG_CACHE_NBR];
static CPU_INT16U AudioSongInfoCacheStart;
static CPU_BOOLEAN AudioUI_DisplaySkip;
static CPU_CHAR AudioUI_MsgUpdate;
static CPU_CHAR AudioUI_MsgRefresh;
static CPU_CHAR AudioUI_MsgNextSong;
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
CPU_INT16U AppProbe_SongLstIx;
CPU_CHAR AppProbe_SongLstName[APP_SONG_NAME_SIZE_MAX + 1];
CPU_INT16U AppProbe_SongPlayIx;
CPU_CHAR AppProbe_SongPlayName[APP_SONG_NAME_SIZE_MAX + 1];
CPU_INT16U AppProbe_SongNbrMax;
CPU_BOOLEAN AppProbe_SongPlayback;
CPU_BOOLEAN AppProbe_SongPaused;
#if (AUDIO_CFG_SSM2377_EN > 0u)
CPU_BOOLEAN AppProbe_AudioLowGain;
#endif
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppGraphLCD_IPAddr ( NET_IF_NBR if_nbr);
#endif
static void AudioUI_Task ( void *p_arg);
static void AudioMgr_Task ( void *p_arg);
static void AudioPlayback_Wave (const CPU_CHAR *filename);
static void AudioPlayback_ADPCM (const CPU_CHAR *filename);
static void AudioUI_Action ( UI_STATE *p_state);
static void AudioUI_DisplayInfo ( CPU_BOOLEAN playback,
CPU_INT16U song_play_ix,
const CPU_CHAR *song_play_name,
CPU_INT16U song_lst_ix,
const CPU_CHAR *song_lst_name,
CPU_INT16U song_lst_nbr_max);
static void AudioUI_DisplayProg ( CPU_INT32U pos,
CPU_INT32U len,
CPU_INT32U samplerate,
CPU_INT08U ch);
static void AudioUI_Update (void);
static void AudioUI_NextSong (void);
static CPU_BOOLEAN AudioMgr_Action (void);
static CPU_BOOLEAN AudioMgr_Start ( CPU_INT16U song_ix);
static CPU_BOOLEAN AudioMgr_Stop (void);
static CPU_BOOLEAN AudioMgr_Pause (void);
static CPU_BOOLEAN Audio_IsPlaying (void);
static void Audio_SetPlayback ( CPU_BOOLEAN playback,
CPU_BOOLEAN paused);
static CPU_BOOLEAN Audio_IsPaused (void);
static CPU_INT16U PlayList_GetNbrFiles (void);
static CPU_BOOLEAN PlayList_GetFileName ( CPU_INT16U song_ix,
CPU_CHAR *p_song_name);
static AUDIO_INFO *PlayList_GetFileInfo ( CPU_INT16U song_ix,
CPU_BOOLEAN force_refresh);
static CPU_INT32U AudioADPCM_GetSamplerate(const CPU_CHAR *p_name);
static void AudioADPCM_GetInfo (const CPU_CHAR *p_name,
AUDIO_INFO *p_info);
static void AudioWave_GetInfo (const CPU_CHAR *p_name,
AUDIO_INFO *p_info);
static CPU_CHAR *FSUtil_GetFileName ( CPU_CHAR *p_name,
const CPU_CHAR *p_fullname,
CPU_SIZE_T len_max);
static CPU_CHAR *FSUtil_GetFileExt ( CPU_CHAR *p_ext,
const CPU_CHAR *p_fullname,
CPU_SIZE_T len_max);
static void LCD_Clr (void);
static void LCD_Msg (const CPU_CHAR *msg_line_1,
const CPU_CHAR *msg_line_2);
static void LCD_Err (const CPU_CHAR *msg_line_1,
const CPU_CHAR *msg_line_2);
static void ADC_TmrInit (void);
static void ADC_Init (void);
static CPU_INT16U ADC_PotRd (void);
#if (AUDIO_CFG_SSM2377_EN > 0u)
static void SSM2377_Init (void);
static void SSM2377_En ( CPU_BOOLEAN en);
static void SSM2377_Gain ( CPU_BOOLEAN high);
#endif
/*
*********************************************************************************************************
* AppAudio_Init()
*
* Description : Initialize audio player.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void AppAudio_Init (void)
{
CPU_BOOLEAN init;
OS_ERR err;
init = Audio_Init(); /* Initialize audio module. */
#if (AUDIO_CFG_SSM2377_EN > 0u)
SSM2377_Init(); /* Initialize audio amplifier. */
#endif
LCD_Clr();
if (init == DEF_TRUE) {
OSTaskCreate((OS_TCB *)&AudioUI_TCB, /* Create audio ui task. */
(CPU_CHAR *)"Audio UI Task",
(OS_TASK_PTR ) AudioUI_Task,
(void *) 0,
(OS_PRIO ) AUDIO_UI_TASK_PRIO,
(CPU_STK *)&AudioUI_TaskStk[0],
(CPU_STK_SIZE) AUDIO_UI_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) AUDIO_UI_TASK_STK_SIZE,
(OS_MSG_QTY ) 10u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AudioMgr_TCB, /* Create audio manager task. */
(CPU_CHAR *)"Audio Manager Task",
(OS_TASK_PTR ) AudioMgr_Task,
(void *) 0,
(OS_PRIO ) AUDIO_MGR_TASK_PRIO,
(CPU_STK *)&AudioMgr_TaskStk[0],
(CPU_STK_SIZE) AUDIO_MGR_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) AUDIO_MGR_TASK_STK_SIZE,
(OS_MSG_QTY ) 2u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSSemCreate((OS_SEM *)&AudioMgr_Sem,
(CPU_CHAR *)"Audio Manager Signal",
(OS_SEM_CTR) 0u,
(OS_ERR *)&err);
} else {
LCD_Msg("Audio Player",
"Failed to Start");
}
ADC_TmrInit();
ADC_Init();
}
/*
*********************************************************************************************************
* AudioUI_Task()
*
* Description : Audio player user interface task.
*
* Argument(s) : p_arg Argument passed to 'AudioUI_Task()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Caller(s) : This is a task.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioUI_Task (void *p_arg)
{
OS_ERR os_err;
FS_ERR fs_err;
CPU_INT32U fs_open_retries;
UI_STATE state;
UI_STATE next_state;
CPU_INT16U song_lst_nbr_max;
CPU_INT16U song_lst_ix;
CPU_CHAR song_lst_name[APP_SONG_NAME_SIZE_MAX + 1];
CPU_INT16U song_play_ix;
CPU_CHAR song_play_name[APP_SONG_NAME_SIZE_MAX + 1];
CPU_BOOLEAN playback;
CPU_BOOLEAN paused;
CPU_BOOLEAN valid;
CPU_BOOLEAN loop;
CPU_INT32U ix;
CPU_SR_ALLOC();
Str_Copy(song_lst_name, "");
Str_Copy(song_play_name, "");
playback = DEF_FALSE;
paused = DEF_FALSE;
song_lst_nbr_max = 0u;
song_lst_ix = 0u;
song_play_ix = 0u;
AppProbe_SongNbrMax = song_lst_nbr_max;
AppProbe_SongLstIx = song_lst_ix;
AppProbe_SongPlayIx = song_play_ix;
AppProbe_SongPlayback = playback;
AppProbe_SongPaused = paused;
Str_Copy(AppProbe_SongLstName, " ");
Str_Copy(AppProbe_SongPlayName, " ");
AudioUI_DisplaySkip = DEF_FALSE;
state = PLAYER_HELP;
next_state = PLAYER_HELP;
while (DEF_TRUE) {
switch (state) {
case PLAYER_HELP:
#if (AUDIO_CFG_SSM2377_EN == 0u)
BSP_GraphLCD_String(2u, "Help: (Press SW2)");
BSP_GraphLCD_String(3u, "SW1 for prev song");
BSP_GraphLCD_String(4u, "SW2 for play/pause");
BSP_GraphLCD_String(5u, "SW3 for next song");
BSP_GraphLCD_String(6u, "SW1+SW2 refresh SD");
BSP_GraphLCD_String(7u, "SW1+SW3 for IP addr");
#else
BSP_GraphLCD_String(2u, "SW1 for prev song");
BSP_GraphLCD_String(3u, "SW2 for play/pause");
BSP_GraphLCD_String(4u, "SW3 for next song");
BSP_GraphLCD_String(5u, "SW1+SW2 refresh SD");
BSP_GraphLCD_String(6u, "SW1+SW3 for IP addr");
BSP_GraphLCD_String(7u, "SW2+SW3 gain ctrl");
#endif
loop = DEF_TRUE;
while (loop == DEF_TRUE) {
if (SWITCH1() && SWITCH3()) {
state = PLAYER_IP;
next_state = PLAYER_HELP;
loop = DEF_FALSE;
#if (AUDIO_CFG_SSM2377_EN > 0u)
} else if (SWITCH2() && SWITCH3()) {
state = PLAYER_GAIN;
next_state = PLAYER_HELP;
loop = DEF_FALSE;
#endif
} else if (SWITCH2()) {
state = SD_WAIT;
loop = DEF_FALSE;
LCD_Clr();
/* Debounce switch. */
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH2());
} else {
OSTimeDlyHMSM(0u, 0u, 0u, 50u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
}
}
break;
case PLAYER_IP:
CPU_CRITICAL_ENTER();
AudioUI_DisplaySkip = DEF_TRUE;
CPU_CRITICAL_EXIT();
ix = 0;
do {
if ((ix % 5) == 0) {
ix = 0;
LCD_Clr();
AppGraphLCD_IPAddr(1u);
}
ix++;
OSTimeDlyHMSM(0u, 0u, 0u, 50u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH1() || SWITCH3()); /* Wait until both SW1 & SW3 released. */
LCD_Clr();
CPU_CRITICAL_ENTER();
AudioUI_DisplaySkip = DEF_FALSE;
CPU_CRITICAL_EXIT();
state = next_state;
break;
#if (AUDIO_CFG_SSM2377_EN > 0u)
case PLAYER_GAIN:
CPU_CRITICAL_ENTER();
AudioUI_DisplaySkip = DEF_TRUE;
CPU_CRITICAL_EXIT();
LCD_Clr();
BSP_GraphLCD_String(2u, "Gain: (Press SW2)");
BSP_GraphLCD_String(4u, " SW1 for low gain");
if (AppProbe_AudioLowGain == DEF_YES) {
BSP_GraphLCD_String(4u, "*");
}
BSP_GraphLCD_String(6u, " SW3 for high gain");
if (AppProbe_AudioLowGain == DEF_NO) {
BSP_GraphLCD_String(6u, "*");
}
do {
OSTimeDlyHMSM(0u, 0u, 0u, 50u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH2() || SWITCH3()); /* Wait until both SW2 & SW3 released. */
while (DEF_ON) {
/* SW1: Low Gain */
if (SWITCH1() && !(SWITCH2() ||SWITCH3())) {
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH1() && !(SWITCH2() || SWITCH3()));
AppProbe_AudioLowGain = DEF_YES;
break;
/* SW3: High Gain */
} else if (SWITCH3() && !(SWITCH1() ||SWITCH2())) {
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH1() && !(SWITCH2() || SWITCH3()));
AppProbe_AudioLowGain = DEF_NO;
break;
/* SW2: Select */
} else if (SWITCH2() && !(SWITCH1() ||SWITCH3())) {
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH2() && !(SWITCH1() || SWITCH3()));
if (AppProbe_AudioLowGain == DEF_YES) {
SSM2377_Gain(DEF_NO);
} else {
SSM2377_Gain(DEF_YES);
}
state = next_state;
CPU_CRITICAL_ENTER();
AudioUI_DisplaySkip = DEF_FALSE;
CPU_CRITICAL_EXIT();
break;
}
OSTimeDlyHMSM(0u, 0u, 0u, 50u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
}
LCD_Clr();
break;
#endif
case SD_WAIT:
Str_Copy(song_lst_name, "");
Str_Copy(song_play_name, "");
playback = DEF_FALSE;
paused = DEF_FALSE;
song_lst_nbr_max = 0u;
song_lst_ix = 0u;
song_play_ix = 0u;
AppProbe_SongNbrMax = song_lst_nbr_max;
AppProbe_SongLstIx = song_lst_ix;
AppProbe_SongPlayIx = song_play_ix;
AppProbe_SongPlayback = playback;
AppProbe_SongPaused = paused;
Str_Copy(AppProbe_SongLstName, " ");
Str_Copy(AppProbe_SongPlayName, " ");
for (ix = 0; ix < APP_SONG_CACHE_NBR; ix++) {
Str_Copy(AudioSongInfoCache[ix].Name, "");
AudioSongInfoCache[ix].NbrCh = 0u;
AudioSongInfoCache[ix].SamplesPerSec = 0u;
AudioSongInfoCache[ix].AvgBytesPerSec = 0u;
AudioSongInfoCache[ix].BitsPerSample = 0u;
AudioSongInfoCache[ix].TimeLen = 0u;
}
AudioSongInfoCacheStart = DEF_INT_16U_MAX_VAL;
LCD_Msg("Press SW2 to load",
"files from SD card");
while (!SWITCH2() || SWITCH1()) {
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
}
/* Debounce switch. */
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH2());
LCD_Clr();
state = SD_OPEN;
break;
case SD_OPEN:
song_lst_ix = 0u;
fs_open_retries = APP_USER_IF_FS_RETRIES_MAX; /* Open file system volume. */
do {
FSVol_Open(APP_AUDIO_FS_VOL, APP_AUDIO_FS_DEV, 0, &fs_err);
fs_open_retries--;
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while ((fs_err != FS_ERR_NONE) &&
(fs_err != FS_ERR_VOL_ALREADY_OPEN) &&
(fs_open_retries > 0));
if ((fs_err != FS_ERR_NONE) &&
(fs_err != FS_ERR_VOL_ALREADY_OPEN)) {
LCD_Err("SD Card Mnt Failed",
"FSVol_Open Err");
state = SD_WAIT;
} else {
state = SD_GETFILES;
}
break;
case SD_GETFILES:
song_lst_nbr_max = PlayList_GetNbrFiles();
if (song_lst_nbr_max > 0u) {
if ((song_lst_ix == 0u) ||
(song_lst_ix > song_lst_nbr_max)) {
song_lst_ix = 1u;
}
(void)PlayList_GetFileInfo(song_lst_ix, DEF_TRUE);
valid = PlayList_GetFileName(song_lst_ix, song_lst_name);
} else {
LCD_Err("No Songs Found",
"in " APP_AUDIO_FS_FOLDER " folder");
valid = DEF_FALSE;
}
if (valid == DEF_TRUE) {
Str_Copy_N(AppProbe_SongLstName, song_lst_name, APP_SONG_NAME_SIZE_MAX);
FSUtil_GetFileName(song_lst_name, song_lst_name, 19u);
AppProbe_SongLstIx = song_lst_ix;
AppProbe_SongNbrMax = song_lst_nbr_max;
state = UI_UPDATE;
} else {
state = SD_WAIT;
}
break;
case UI_UPDATE:
playback = Audio_IsPlaying();
AudioUI_DisplayInfo(playback,
song_play_ix,
song_play_name,
song_lst_ix,
song_lst_name,
song_lst_nbr_max);
state = UI_WAIT_ACTION;
break;
case UI_WAIT_ACTION:
next_state = UI_UPDATE;
AudioUI_Action(&state);
break;
case PLAYLIST_PREV:
if (song_lst_ix > 1) {
song_lst_ix--;
} else {
song_lst_ix = song_lst_nbr_max;
}
valid = PlayList_GetFileName(song_lst_ix, song_lst_name);
if (valid == DEF_TRUE) {
Str_Copy_N(AppProbe_SongLstName, song_lst_name, APP_SONG_NAME_SIZE_MAX);
FSUtil_GetFileName(song_lst_name, song_lst_name, 19);
AppProbe_SongLstIx = song_lst_ix;
state = UI_UPDATE;
} else {
state = SD_WAIT;
}
break;
case PLAYLIST_NEXT:
if (song_lst_ix < song_lst_nbr_max) {
song_lst_ix++;
} else {
song_lst_ix = 1;
}
valid = PlayList_GetFileName(song_lst_ix, song_lst_name);
if (valid == DEF_TRUE) {
Str_Copy_N(AppProbe_SongLstName, song_lst_name, APP_SONG_NAME_SIZE_MAX);
FSUtil_GetFileName(song_lst_name, song_lst_name, 19);
AppProbe_SongLstIx = song_lst_ix;
state = UI_UPDATE;
} else {
state = SD_WAIT;
}
break;
case PLAYLIST_SELECT:
playback = Audio_IsPlaying();
if (playback) {
if (song_play_ix != song_lst_ix) {
state = PLAYBACK_STOP_START;
} else {
state = PLAYBACK_PAUSE;
}
} else {
paused = Audio_IsPaused();
if (paused &&
(song_play_ix == song_lst_ix)) {
state = PLAYBACK_START;
} else {
state = PLAYBACK_STOP_START;
}
}
break;
case PLAYBACK_SELECT_NEXT:
if (song_play_ix < song_lst_nbr_max) {
song_play_ix++;
} else {
song_play_ix = 1;
}
state = PLAYBACK_PLAY;
break;
case PLAYBACK_PAUSE:
(void)AudioMgr_Pause();
state = UI_UPDATE;
break;
case PLAYBACK_STOP_START:
valid = AudioMgr_Stop();
if (valid == DEF_OK) {
state = PLAYBACK_START;
} else {
state = UI_UPDATE;
}
break;
case PLAYBACK_START:
paused = Audio_IsPaused();
if (paused) {
valid = AudioMgr_Start(song_play_ix);
if (valid != DEF_TRUE) {
Str_Copy(song_play_name, "");
Str_Copy(AppProbe_SongPlayName, " ");
}
state = UI_UPDATE;
} else {
song_play_ix = song_lst_ix;
state = PLAYBACK_PLAY;
}
break;
case PLAYBACK_PLAY:
valid = PlayList_GetFileName(song_play_ix, song_play_name);
if (valid == DEF_TRUE) {
valid = AudioMgr_Start(song_play_ix);
if (valid == DEF_TRUE) {
Str_Copy_N(AppProbe_SongPlayName, song_play_name, APP_SONG_NAME_SIZE_MAX);
FSUtil_GetFileName(song_play_name, song_play_name, 19);
} else {
Str_Copy(song_play_name, "");
Str_Copy(AppProbe_SongPlayName, " ");
}
AppProbe_SongPlayIx = song_play_ix;
state = UI_UPDATE;
} else {
state = SD_WAIT;
}
break;
}
}
}
/*
*********************************************************************************************************
* AudioMgr_Task()
*
* Description : Manages playback of an audio file.
*
* Argument(s) : p_arg Argument passed to 'AudioMgr_Task()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Caller(s) : This is a task.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioMgr_Task (void *p_arg)
{
/* Allow space for directory name. */
CPU_CHAR fullname[APP_SONG_NAME_SIZE_MAX + sizeof(APP_AUDIO_FS_FOLDER) + 1];
CPU_CHAR *p_filename;
CPU_CHAR file_ext[4 + 1];
CPU_CHAR *p_ext;
AUDIO_MGR_MSG *p_msg;
OS_MSG_SIZE msg_size;
CPU_BOOLEAN valid;
CPU_SIZE_T len;
OS_ERR os_err;
(void)p_arg;
Audio_SetPlayback(DEF_FALSE, DEF_FALSE);
while (DEF_TRUE) {
/* Wait for a file to be played. */
p_msg = (AUDIO_MGR_MSG *)OSTaskQPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
if (os_err != OS_ERR_NONE) {
continue;
}
Audio_SetPlayback(DEF_FALSE, DEF_FALSE);
OSSemPost(&AudioMgr_Sem, /* Ack msg to Audio UI. */
OS_OPT_POST_1,
&os_err);
if (msg_size != sizeof(AUDIO_MGR_MSG)) {
continue;
}
if (p_msg->ID != MSG_START) {
continue;
}
Str_Copy(fullname, APP_AUDIO_FS_FOLDER);
len = Str_Len(fullname);
p_filename = &fullname[len];
valid = PlayList_GetFileName(p_msg->SongIx, p_filename);
if (valid == DEF_FAIL) {
continue;
}
p_ext = FSUtil_GetFileExt(file_ext, p_filename, 4);
if (Str_CmpIgnoreCase_N(p_ext, "wav", 4) == 0) { /* RIFF WAVE file. */
AudioPlayback_Wave(fullname);
} else if (Str_CmpIgnoreCase_N(p_ext, "dat", 4) == 0) { /* ADPCM file. */
AudioPlayback_ADPCM(fullname);
} else {
LCD_Err("Invalid Audio File",
"Unknown Extension");
}
}
}
/*
*********************************************************************************************************
* AudioPlayback_Wave()
*
* Description : Process Wave file for playback.
*
* Argument(s) : filename Pointer to file name.
*
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioPlayback_Wave (const CPU_CHAR *filename)
{
CPU_BOOLEAN open;
AUDIO_BUF *p_audio_buf;
FS_FILE *p_file;
CPU_SIZE_T octets_rd;
CPU_SIZE_T len;
CPU_INT32U size_rem;
RIFF_FMT riff_fmt;
RIFF_CHUNK riff_chunk;
PCM_WAVE_FMT pcm_wave_fmt;
FS_ERR fs_err;
CPU_BOOLEAN song_end;
CPU_BOOLEAN song_stop;
CPU_SIZE_T samples_max;
CPU_SIZE_T octets;
CPU_INT32U size_th;
CPU_INT32U size_prog;
LCD_Err("", ""); /* Clr err msgs. */
p_file = FSFile_Open((CPU_CHAR *)filename,
FS_FILE_ACCESS_MODE_RD |
FS_FILE_ACCESS_MODE_CACHED,
&fs_err);
if (fs_err != FS_ERR_NONE) {
LCD_Err("SD Card Read Failed",
"FSFile_Open Err");
return;
}
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *)&riff_fmt,
(CPU_SIZE_T) sizeof(RIFF_FMT),
(FS_ERR *)&fs_err);
if((fs_err != FS_ERR_NONE) ||
(octets_rd != sizeof(RIFF_FMT)) ||
(riff_fmt.Chunk.ID != RIFF_CHUNK_ID) ||
(riff_fmt.Fmt != RIFF_CHUNK_TYPE_WAVE)) {
FSFile_Close(p_file, &fs_err);
if (fs_err != FS_ERR_NONE) {
LCD_Err("SD Card Read Failed",
"FSFile_Rd Err");
} else {
LCD_Err("Invalid Wave File",
"");
}
return;
}
song_end = DEF_NO;
song_stop = DEF_NO;
while ((song_end == DEF_NO) &&
(song_stop == DEF_NO)) {
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *)&riff_chunk,
(CPU_SIZE_T) sizeof(RIFF_CHUNK),
(FS_ERR *)&fs_err);
if ((fs_err != FS_ERR_NONE) ||
(octets_rd != sizeof(RIFF_CHUNK))) {
song_end = DEF_YES;
continue;
}
switch (riff_chunk.ID) {
case RIFF_WAVE_CHUNK_ID_FMT:
Mem_Clr(&pcm_wave_fmt, sizeof(PCM_WAVE_FMT));
len = DEF_MIN(riff_chunk.Size, sizeof(PCM_WAVE_FMT));
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *)&pcm_wave_fmt,
(CPU_SIZE_T) len,
(FS_ERR *)&fs_err);
if ((fs_err != FS_ERR_NONE) ||
(octets_rd != len)) {
song_end = DEF_YES;
LCD_Err("SD Card Read Failed",
"FSFile_Rd Err (Fmt)");
continue;
}
if (pcm_wave_fmt.FmtTag != RIFF_WAVE_FMT_TAG_PCM) {
song_end = DEF_YES;
LCD_Err("Invalid Wave File",
"Unsupported Format");
continue;
}
/* Skip additional fmt fields. */
if (riff_chunk.Size > sizeof(PCM_WAVE_FMT)) {
len = riff_chunk.Size - sizeof(PCM_WAVE_FMT);
FSFile_PosSet((FS_FILE *) p_file,
(FS_FILE_OFFSET) len,
(FS_STATE ) FS_FILE_ORIGIN_CUR,
(FS_ERR *)&fs_err);
if (fs_err != FS_ERR_NONE) {
song_end = DEF_YES;
LCD_Err("SD Card Read Failed",
"FSFile_PosSet Err");
continue;
}
}
switch (pcm_wave_fmt.BitsPerSample) {
case 8u:
open = AudioStream_Open(AUDIO_STREAM_FMT_08_UNSIGNED,
pcm_wave_fmt.NbrCh,
pcm_wave_fmt.SamplesPerSec,
&samples_max);
break;
case 16u:
open = AudioStream_Open(AUDIO_STREAM_FMT_16_SIGNED,
pcm_wave_fmt.NbrCh,
pcm_wave_fmt.SamplesPerSec,
&samples_max);
break;
default:
song_end = DEF_YES;
continue;
}
if (open == DEF_YES) {
octets = AudioUtil_SamplesToOctets(samples_max);
Audio_SetPlayback(DEF_TRUE, DEF_FALSE);
AudioUI_Update();
} else {
song_end = DEF_YES;
LCD_Err("Invalid Audio File",
"Stream Open Failed");
continue;
}
break;
case RIFF_WAVE_CHUNK_ID_DATA:
size_prog = 0u;
/* Threshold to display progress: MIN(500ms, 0.5%). */
size_th = DEF_MIN(AudioUtil_TimeToOctets(500) * pcm_wave_fmt.NbrCh,
riff_chunk.Size / 200);
size_rem = riff_chunk.Size;
AudioUI_DisplayProg(riff_chunk.Size - size_rem,
riff_chunk.Size,
pcm_wave_fmt.SamplesPerSec,
pcm_wave_fmt.NbrCh);
while ((song_end == DEF_NO) &&
(song_stop == DEF_NO) &&
(size_rem != 0u)) {
p_audio_buf = AudioBuf_Get();
if (p_audio_buf == (AUDIO_BUF *)0) {
song_end = DEF_YES;
continue;
}
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *) p_audio_buf->DataPtr,
(CPU_SIZE_T) DEF_MIN(size_rem, octets),
(FS_ERR *)&fs_err);
p_audio_buf->Samples = AudioUtil_OctetsToSamples(octets_rd);
if ((fs_err == FS_ERR_NONE) &&
(octets_rd > 0)) {
size_rem -= octets_rd;
size_prog += octets_rd;
if (size_prog > size_th) {
size_prog %= size_th;
AudioUI_DisplayProg(riff_chunk.Size - size_rem,
riff_chunk.Size,
pcm_wave_fmt.SamplesPerSec,
pcm_wave_fmt.NbrCh);
song_stop = AudioMgr_Action();
}
AudioBuf_Enqueue(p_audio_buf);
if (octets_rd != octets) { /* Chk if EOF. */
song_end = DEF_YES;
}
} else {
AudioBuf_Abort(p_audio_buf);
song_end = DEF_YES;
}
}
AudioUI_DisplayProg(riff_chunk.Size - size_rem,
riff_chunk.Size,
pcm_wave_fmt.SamplesPerSec,
pcm_wave_fmt.NbrCh);
break;
default:
FSFile_PosSet((FS_FILE *) p_file,
(FS_FILE_OFFSET) riff_chunk.Size,
(FS_STATE ) FS_FILE_ORIGIN_CUR,
(FS_ERR *)&fs_err);
if (fs_err != FS_ERR_NONE) {
song_end = DEF_YES;
continue;
}
break;
}
}
FSFile_Close(p_file, &fs_err);
AudioStream_Close();
Audio_SetPlayback(DEF_FALSE, DEF_FALSE);
if (song_stop == DEF_NO) {
AudioUI_NextSong();
} else {
AudioUI_Update();
}
}
/*
*********************************************************************************************************
* AudioPlayback_ADPCM()
*
* Description : Process ADPCM file for playback.
*
* Argument(s) : filename Pointer to file name.
*
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioPlayback_ADPCM (const CPU_CHAR *filename)
{
CPU_CHAR *p_samplerate;
CPU_INT32U samplerate;
CPU_BOOLEAN open;
AUDIO_BUF *p_audio_buf;
FS_FILE *p_file;
CPU_SIZE_T octets_rd;
CPU_INT32U size_rem;
FS_ERR fs_err;
CPU_BOOLEAN song_end;
CPU_BOOLEAN song_stop;
CPU_SIZE_T samples_max;
CPU_SIZE_T octets;
CPU_INT32U size_th;
CPU_INT32U size_prog;
FS_ENTRY_INFO fs_info;
p_samplerate = Str_Char_Last(filename, '-');
if (p_samplerate == (CPU_CHAR *)0) {
LCD_Err("Invalid ADPCM File",
"No Sample Rate Info");
return;
}
samplerate = Str_ParseNbr_Int32U( &p_samplerate[1],
(CPU_CHAR **)0,
DEF_NBR_BASE_DEC);
switch (samplerate) {
case 8000u:
case 11025u:
case 16000u:
case 22050u:
case 24000u:
case 32000u:
case 44100u:
case 48000u:
break;
default:
LCD_Err("Invalid ADPCM File",
"Sample Rate Invalid");
return;
}
song_end = DEF_NO;
song_stop = DEF_NO;
Audio_SetPlayback(DEF_TRUE, DEF_FALSE);
AudioUI_Update();
LCD_Err("", ""); /* Clr err msgs. */
p_file = FSFile_Open((CPU_CHAR *)filename,
FS_FILE_ACCESS_MODE_RD |
FS_FILE_ACCESS_MODE_CACHED,
&fs_err);
if (fs_err != FS_ERR_NONE) {
LCD_Err("SD Card Read Failed",
"FSFile_Open Err");
return;
}
FSFile_Query(p_file, &fs_info, &fs_err);
if (fs_err != FS_ERR_NONE) {
LCD_Err("SD Card Read Failed",
"FSFile_Query Err");
return;
}
open = AudioStream_Open(AUDIO_STREAM_FMT_04_ADPCM,
1u,
samplerate,
&samples_max);
if (open != DEF_YES) {
song_end = DEF_YES;
LCD_Err("Invalid Audio File",
"Stream Open Failed");
}
size_prog = 0u;
octets = AudioUtil_SamplesToOctets(samples_max);
size_th = DEF_MIN(AudioUtil_TimeToOctets(500), /* Threshold to display progress: MIN(500ms, 0.5%). */
fs_info.Size / 200);
size_rem = fs_info.Size;
AudioUI_DisplayProg(fs_info.Size - size_rem,
fs_info.Size,
samplerate,
1u);
while ((song_end == DEF_NO) &&
(song_stop == DEF_NO) &&
(size_rem != 0u)) {
p_audio_buf = AudioBuf_Get();
if (p_audio_buf == (AUDIO_BUF *)0) {
song_end = DEF_YES;
continue;
}
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *) p_audio_buf->DataPtr,
(CPU_SIZE_T) DEF_MIN(size_rem, octets),
(FS_ERR *)&fs_err);
p_audio_buf->Samples = AudioUtil_OctetsToSamples(octets_rd);
if ((fs_err == FS_ERR_NONE) &&
(octets_rd > 0)) {
size_rem -= octets_rd;
size_prog += octets_rd;
if (size_prog > size_th) {
size_prog %= size_th;
AudioUI_DisplayProg(fs_info.Size - size_rem,
fs_info.Size,
samplerate,
1u);
song_stop = AudioMgr_Action();
}
AudioBuf_Enqueue(p_audio_buf);
if (octets_rd != octets) { /* Chk if EOF. */
song_end = DEF_YES;
}
} else {
AudioBuf_Abort(p_audio_buf);
song_end = DEF_YES;
}
}
AudioUI_DisplayProg(fs_info.Size - size_rem,
fs_info.Size,
samplerate,
1u);
FSFile_Close(p_file, &fs_err);
AudioStream_Close();
Audio_SetPlayback(DEF_FALSE, DEF_FALSE);
if (song_stop == DEF_NO) {
AudioUI_NextSong();
} else {
AudioUI_Update();
}
}
/*
*********************************************************************************************************
* AudioUI_Action()
*
* Description : Process input actions for user interface.
*
* Argument(s) : p_state Pointer to return user interface state after input.
*
* Return(s) : none.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioUI_Action (UI_STATE *p_state)
{
static CPU_INT08U prev_button = 0u;
static CPU_INT08U prev_cnt = 0u;
CPU_INT08U button_th;
CPU_BOOLEAN loop;
CPU_INT16U vol;
OS_TICK timeout;
OS_ERR os_err;
void *p_msg;
OS_MSG_SIZE msg_size;
if (p_state == (UI_STATE *)0) {
return;
}
loop = DEF_TRUE;
while (loop == DEF_TRUE) {
if (SWITCH1() && SWITCH3()) {
*p_state = PLAYER_IP;
loop = DEF_FALSE;
prev_button = 0u;
} else if (SWITCH1() && SWITCH2()) {
AudioMgr_Stop();
LCD_Clr();
*p_state = SD_WAIT;
loop = DEF_FALSE;
prev_button = 0u;
#if (AUDIO_CFG_SSM2377_EN > 0u)
} else if (SWITCH2() && SWITCH3()) {
*p_state = PLAYER_GAIN;
loop = DEF_FALSE;
prev_button = 0u;
#endif
} else if (SWITCH1()) { /* SW1: Previous */
if (prev_button != 1u) {
prev_cnt = 0u;
} else {
if (prev_cnt < 24u) {
prev_cnt++;
}
}
button_th = 250u / (prev_cnt + 7u);
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
button_th--;
} while (SWITCH1() && !SWITCH2() && (button_th > 0u));
if (SWITCH2()) {
AudioMgr_Stop();
LCD_Clr();
*p_state = SD_WAIT;
} else {
*p_state = PLAYLIST_PREV;
}
loop = DEF_FALSE;
prev_button = 1u;
} else if (SWITCH2()) { /* SW2: Select */
prev_cnt = 0u;
/* Debounce switch. */
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
} while (SWITCH2() && !SWITCH1());
if (SWITCH1()) {
AudioMgr_Stop();
LCD_Clr();
*p_state = SD_WAIT;
} else {
*p_state = PLAYLIST_SELECT;
}
loop = DEF_FALSE;
prev_button = 2u;
} else if (SWITCH3()) { /* SW3: Next */
if (prev_button != 3u) {
prev_cnt = 0u;
} else {
if (prev_cnt < 24u) {
prev_cnt++;
}
}
button_th = 250u / (prev_cnt + 7u);
do {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&os_err);
button_th--;
} while (SWITCH3() && (button_th > 0u));
*p_state = PLAYLIST_NEXT;
loop = DEF_FALSE;
prev_button = 3u;
} else {
if (prev_button != 0u) {
prev_cnt = 0u;
} else {
if (prev_cnt < 10u) {
prev_cnt++;
}
}
if (prev_cnt >= 10u) {
prev_cnt = 0u;
vol = ADC_PotRd();
vol /= 762u; /* Limit volume to 86% to avoid artifacts in output. */
AudioStream_VolSet(vol);
}
prev_button = 0u;
timeout = 25u * DEF_TIME_NBR_mS_PER_SEC /
OSCfg_TickRate_Hz;
p_msg = OSTaskQPend( timeout,
OS_OPT_PEND_BLOCKING,
&msg_size,
(CPU_TS *)0,
&os_err);
if (os_err == OS_ERR_NONE) { /* Recv'd async signal. */
if (p_msg == &AudioUI_MsgUpdate) {
*p_state = UI_UPDATE;
loop = DEF_FALSE;
} else if (p_msg == &AudioUI_MsgRefresh) {
*p_state = SD_GETFILES;
loop = DEF_FALSE;
} else if (p_msg == &AudioUI_MsgNextSong) {
*p_state = PLAYBACK_SELECT_NEXT;
loop = DEF_FALSE;
}
}
}
}
}
/*
*********************************************************************************************************
* AudioUI_DisplayInfo()
*
* Description : Display audio information on user interface.
*
* Argument(s) : playback Audio player is in playback mode.
*
* song_play_ix Index of playback song.
*
* song_play_name Pointer to name of playback song.
*
* song_lst_ix Index of currently selected song.
*
* song_lst_name Pointer to name of currently selected song.
*
* song_lst_nbr_max Maximum number of songs.
*
* Return(s) : none.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioUI_DisplayInfo ( CPU_BOOLEAN playback,
CPU_INT16U song_play_ix,
const CPU_CHAR *song_play_name,
CPU_INT16U song_lst_ix,
const CPU_CHAR *song_lst_name,
CPU_INT16U song_lst_nbr_max)
{
CPU_CHAR songs_msg[10 + 1];
CPU_CHAR songs_max_msg[3 + 1];
CPU_INT32U tot_time;
CPU_CHAR str_time_sec[3];
CPU_CHAR str_tot_time[6];
CPU_CHAR str_bps_ch[8];
CPU_CHAR str_samplerate[6];
CPU_BOOLEAN valid;
AUDIO_INFO *p_info;
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SYMBOL);
BSP_GraphLCD_CharPixel(2u, 0u, 1u); /* Previous symbol. */
if (playback) {
if (song_play_ix == song_lst_ix) {
BSP_GraphLCD_CharPixel(2u, 15u, 5u); /* Pause symbol. */
} else {
BSP_GraphLCD_CharPixel(2u, 15u, 3u); /* Play symbol. */
}
} else {
BSP_GraphLCD_CharPixel(2u, 15u, 3u); /* Play symbol. */
}
BSP_GraphLCD_CharPixel(2u, 30u, 2u); /* Next symbol. */
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SMALL);
Str_FmtNbr_Int32U(song_lst_ix,
3u,
DEF_NBR_BASE_DEC,
' ',
DEF_NO,
DEF_YES,
songs_msg);
Str_FmtNbr_Int32U((song_lst_nbr_max > 999) ? 999 : song_lst_nbr_max,
3u,
DEF_NBR_BASE_DEC,
ASCII_CHAR_NUL,
DEF_NO,
DEF_YES,
songs_max_msg);
Str_Cat(songs_msg, "/");
Str_Cat(songs_msg, songs_max_msg);
BSP_GraphLCD_StringPosLen(2u, 19u - Str_Len(songs_msg), songs_msg, 17u);
BSP_GraphLCD_ClrLine(3u);
BSP_GraphLCD_StringPosLen(3u, 0u, song_lst_name, 19u);
p_info = PlayList_GetFileInfo(song_lst_ix, DEF_FALSE);
if (p_info != (AUDIO_INFO *)0) {
valid = p_info->Valid;
if (valid) {
tot_time = p_info->TimeLen;
Str_FmtNbr_Int32U((tot_time / 60u) > 99u ? 99u : (tot_time / 60u),
2u,
DEF_NBR_BASE_DEC,
' ',
DEF_NO,
DEF_YES,
str_tot_time);
Str_FmtNbr_Int32U((tot_time / 60u) > 99u ? 99u : (tot_time % 60u),
2u,
DEF_NBR_BASE_DEC,
'0',
DEF_NO,
DEF_YES,
str_time_sec);
Str_Cat(str_tot_time, ":");
Str_Cat(str_tot_time, str_time_sec);
Str_FmtNbr_Int32U(p_info->BitsPerSample,
2u,
DEF_NBR_BASE_DEC,
' ',
DEF_NO,
DEF_YES,
str_bps_ch);
Str_Cat(str_bps_ch, "b");
switch (p_info->NbrCh) {
case 1u:
Str_Cat(str_bps_ch, "/1ch");
break;
case 2u:
Str_Cat(str_bps_ch, "/2ch");
break;
}
Str_FmtNbr_Int32U(p_info->SamplesPerSec,
5u,
DEF_NBR_BASE_DEC,
' ',
DEF_NO,
DEF_YES,
str_samplerate);
BSP_GraphLCD_ClrLine(4u);
BSP_GraphLCD_StringPos(4u, 0u, str_bps_ch);
BSP_GraphLCD_StringPos(4u, 8u, str_samplerate);
BSP_GraphLCD_StringPos(4u, 14u, str_tot_time);
} else {
BSP_GraphLCD_ClrLine(4u);
BSP_GraphLCD_StringPos(4u, 14u, " -:--");
}
}
if (song_play_ix > 0u) {
BSP_GraphLCD_ClrLine(5u);
BSP_GraphLCD_StringPosLen(5u, 0u, song_play_name, 19u);
}
}
/*
*********************************************************************************************************
* AudioUI_DisplayProg()
*
* Description : Display progress of playback audio on user interface.
*
* Argument(s) : pos Song current position in octets.
*
* len Song length in octets.
*
* samplerate Song sample rate in cycles per second.
*
* ch Song number of channels.
*
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioUI_DisplayProg (CPU_INT32U pos,
CPU_INT32U len,
CPU_INT32U samplerate,
CPU_INT08U ch)
{
CPU_INT32U per;
CPU_INT32U tot_time;
CPU_INT64U cur_time;
CPU_SIZE_T samples;
CPU_CHAR str_time_sec[3];
CPU_CHAR str_cur_time[6];
CPU_CHAR str_tot_time[6];
CPU_BOOLEAN skip;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
skip = AudioUI_DisplaySkip;
CPU_CRITICAL_EXIT();
if (skip == DEF_TRUE) {
return;
}
per = pos / (len / 100u);
samples = AudioUtil_OctetsToSamples(len);
samples /= ch;
tot_time = (samples + samplerate / 2u)/ samplerate;
cur_time = tot_time;
cur_time *= pos;
cur_time /= len;
Str_FmtNbr_Int32U((cur_time / 60u) > 99u ? 99u : (cur_time / 60u),
2u,
DEF_NBR_BASE_DEC,
' ',
DEF_NO,
DEF_YES,
str_cur_time);
Str_FmtNbr_Int32U((cur_time / 60u) > 99u ? 99u : (cur_time % 60u),
2u,
DEF_NBR_BASE_DEC,
'0',
DEF_NO,
DEF_YES,
str_time_sec);
Str_Cat(str_cur_time, ":");
Str_Cat(str_cur_time, str_time_sec);
Str_FmtNbr_Int32U((tot_time / 60u) > 99u ? 99u : (tot_time / 60u),
2u,
DEF_NBR_BASE_DEC,
' ',
DEF_NO,
DEF_YES,
str_tot_time);
Str_FmtNbr_Int32U((tot_time / 60u) > 99u ? 99u : (tot_time % 60u),
2u,
DEF_NBR_BASE_DEC,
'0',
DEF_NO,
DEF_YES,
str_time_sec);
Str_Cat(str_tot_time, ":");
Str_Cat(str_tot_time, str_time_sec);
BSP_GraphLCD_StringPos(6u, 0u, str_cur_time);
BSP_GraphLCD_StringPos(6u, 14u, str_tot_time);
BSP_GraphLCD_ProgBarPos(7u, per);
}
/*
*********************************************************************************************************
* AudioUI_RefreshFiles()
*
* Description : Signal user interface to refresh list of files.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void AudioUI_RefreshFiles (void)
{
OS_ERR os_err;
OSTaskQPost(&AudioUI_TCB,
&AudioUI_MsgRefresh,
sizeof(void *),
OS_OPT_POST_FIFO,
&os_err);
}
/*
*********************************************************************************************************
* AudioUI_Update()
*
* Description : Signal user interface to update information.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioUI_Update (void)
{
OS_ERR os_err;
OSTaskQPost(&AudioUI_TCB,
&AudioUI_MsgUpdate,
sizeof(void *),
OS_OPT_POST_FIFO,
&os_err);
}
/*
*********************************************************************************************************
* AudioUI_NextSong()
*
* Description : Signal user interface to play next song.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioUI_NextSong (void)
{
OS_ERR os_err;
OSTaskQPost(&AudioUI_TCB,
&AudioUI_MsgNextSong,
sizeof(void *),
OS_OPT_POST_FIFO,
&os_err);
}
/*
*********************************************************************************************************
* AudioMgr_Action()
*
* Description : Query if any action message has been posted by user interface.
*
* Argument(s) : none.
*
* Return(s) : DEF_YES, if user interface is requesting playback to stop.
* DEF_NO, otherwise.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN AudioMgr_Action (void)
{
CPU_BOOLEAN song_end;
AUDIO_MGR_MSG *p_msg;
OS_MSG_SIZE msg_size;
CPU_BOOLEAN valid;
OS_ERR os_err;
song_end = DEF_NO;
/* Check for Stop/Pause msg. */
p_msg = (AUDIO_MGR_MSG *)OSTaskQPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_NON_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
if (os_err == OS_ERR_NONE) {
switch (p_msg->ID) {
case MSG_STOP:
Audio_SetPlayback(DEF_FALSE, DEF_FALSE);
song_end = DEF_YES;
valid = DEF_YES;
break;
case MSG_PAUSE:
Audio_SetPlayback(DEF_FALSE, DEF_TRUE);
valid = DEF_YES;
break;
default:
valid = DEF_NO;
break;
}
OSSemPost(&AudioMgr_Sem, /* Ack msg to Audio UI. */
OS_OPT_POST_1,
&os_err);
if (valid == DEF_NO) {
return (DEF_NO);
}
if (p_msg->ID == MSG_PAUSE) {
/* Wait for Stop/Play msg. */
p_msg = (AUDIO_MGR_MSG *)OSTaskQPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
if (os_err == OS_ERR_NONE) {
switch (p_msg->ID) {
case MSG_STOP:
Audio_SetPlayback(DEF_FALSE, DEF_FALSE);
song_end = DEF_YES;
valid = DEF_YES;
break;
case MSG_START:
Audio_SetPlayback(DEF_TRUE, DEF_FALSE);
valid = DEF_YES;
break;
default:
valid = DEF_NO;
break;
}
OSSemPost(&AudioMgr_Sem, /* Ack msg to Audio UI. */
OS_OPT_POST_1,
&os_err);
if (valid == DEF_NO) {
return (DEF_YES);
}
}
}
}
return (song_end);
}
/*
*********************************************************************************************************
* AudioMgr_Start()
*
* Description : Submit message to audio manager to start song playback.
*
* Argument(s) : song_ix Index of song to start playback.
*
* Return(s) : DEF_OK, if message submitted successfully.
* DEF_FAIL, otherwise.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN AudioMgr_Start (CPU_INT16U song_ix)
{
OS_ERR os_err;
AudioMgr_MsgStart.ID = MSG_START;
AudioMgr_MsgStart.SongIx = song_ix;
OSTaskQPost(&AudioMgr_TCB,
&AudioMgr_MsgStart,
sizeof(AUDIO_MGR_MSG),
OS_OPT_POST_FIFO,
&os_err);
if (os_err == OS_ERR_NONE) {
OSSemPend((OS_SEM *)&AudioMgr_Sem,
(OS_TICK ) OSCfg_TickRate_Hz,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
return (DEF_OK);
} else {
return (DEF_FAIL);
}
}
/*
*********************************************************************************************************
* AudioMgr_Stop()
*
* Description : Submit message to audio manager to stop song playback.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if message submitted successfully.
* DEF_FAIL, otherwise.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN AudioMgr_Stop (void)
{
OS_ERR os_err;
AudioMgr_MsgStop.ID = MSG_STOP;
AudioMgr_MsgStop.SongIx = 0;
OSTaskQPost(&AudioMgr_TCB,
&AudioMgr_MsgStop,
sizeof(AUDIO_MGR_MSG),
OS_OPT_POST_FIFO,
&os_err);
if (os_err == OS_ERR_NONE) {
OSSemPend((OS_SEM *)&AudioMgr_Sem,
(OS_TICK ) OSCfg_TickRate_Hz,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
return (DEF_OK);
} else {
return (DEF_FAIL);
}
}
/*
*********************************************************************************************************
* AudioMgr_Pause()
*
* Description : Submit message to audio manager to pause song playback.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if message submitted successfully.
* DEF_FAIL, otherwise.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN AudioMgr_Pause (void)
{
OS_ERR os_err;
AudioMgr_MsgStop.ID = MSG_PAUSE;
AudioMgr_MsgStop.SongIx = 0;
OSTaskQPost(&AudioMgr_TCB,
&AudioMgr_MsgStop,
sizeof(AUDIO_MGR_MSG),
OS_OPT_POST_FIFO,
&os_err);
if (os_err == OS_ERR_NONE) {
OSSemPend((OS_SEM *)&AudioMgr_Sem,
(OS_TICK ) OSCfg_TickRate_Hz,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *) 0,
(OS_ERR *)&os_err);
return (DEF_OK);
} else {
return (DEF_FAIL);
}
}
/*
*********************************************************************************************************
* Audio_IsPlaying()
*
* Description : Retrieve audio playback state.
*
* Argument(s) : none.
*
* Return(s) : DEF_TRUE, if audio is in playback mode.
* DEF_FALSE, otherwise.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN Audio_IsPlaying (void)
{
CPU_BOOLEAN playback;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
playback = Audio_Playback;
CPU_CRITICAL_EXIT();
return (playback);
}
/*
*********************************************************************************************************
* Audio_SetPlayback()
*
* Description : Set audio playback mode.
*
* Argument(s) : playback Playback state.
*
* paused Pause state.
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void Audio_SetPlayback (CPU_BOOLEAN playback,
CPU_BOOLEAN paused)
{
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
Audio_Playback = playback;
AppProbe_SongPlayback = playback;
Audio_Paused = paused;
AppProbe_SongPaused = paused;
CPU_CRITICAL_EXIT();
}
/*
*********************************************************************************************************
* Audio_IsPaused()
*
* Description : Retrieve audio paused state.
*
* Argument(s) : none.
*
* Return(s) : DEF_TRUE, if audio is paused.
* DEF_FALSE, otherwise.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN Audio_IsPaused (void)
{
CPU_BOOLEAN paused;
CPU_SR_ALLOC();
CPU_CRITICAL_ENTER();
paused = Audio_Paused;
CPU_CRITICAL_EXIT();
return (paused);
}
/*
*********************************************************************************************************
* PlayList_GetNbrFiles()
*
* Description : Retrieve the number of supported songs.
*
* Argument(s) : none.
*
* Return(s) : Number of supported songs.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_INT16U PlayList_GetNbrFiles (void)
{
FS_ERR fs_err;
FS_DIR *p_dir;
FS_DIR_ENTRY fs_dir_entry;
CPU_INT16U fs_dir_entry_cnt;
CPU_SIZE_T fs_file_name_len;
CPU_CHAR fs_file_ext[4 + 1];
CPU_CHAR *p_file_ext_cmp;
CPU_INT32U samplerate;
p_dir = FSDir_Open((CPU_CHAR *)APP_AUDIO_FS_FOLDER,
(FS_ERR *)&fs_err);
if (fs_err != FS_ERR_NONE) {
return (0);
}
/* Retrieve number of songs on a directory. */
fs_dir_entry_cnt = 0u;
fs_err = FS_ERR_NONE;
while (fs_err == FS_ERR_NONE) {
FSDir_Rd((FS_DIR *) p_dir, /* Read directory entry. */
(FS_DIR_ENTRY *)&fs_dir_entry,
(FS_ERR *)&fs_err);
if (fs_err == FS_ERR_EOF) {
continue;
}
/* Get entry name length. */
fs_file_name_len = Str_Len_N(fs_dir_entry.Name,
APP_SONG_NAME_SIZE_MAX + 1);
/* Ignore invalid entry name sizes. */
if ((fs_file_name_len > APP_SONG_NAME_SIZE_MAX) ||
(fs_file_name_len < APP_SONG_NAME_SIZE_MIN)) {
continue;
}
p_file_ext_cmp = FSUtil_GetFileExt(fs_file_ext, fs_dir_entry.Name, 4);
/* Check if the entry is a "wav" file. */
if (Str_CmpIgnoreCase_N(p_file_ext_cmp, "wav", 4) == 0) {
fs_dir_entry_cnt++; /* Increment number of songs. */
}
/* Check if the entry is a "dat" file. */
if (Str_CmpIgnoreCase_N(p_file_ext_cmp, "dat", 4) == 0) {
samplerate = AudioADPCM_GetSamplerate(fs_dir_entry.Name);
if (samplerate > 0u) {
fs_dir_entry_cnt++; /* Increment number of songs. */
}
}
}
if (fs_err != FS_ERR_EOF) {
fs_dir_entry_cnt = 0u;
}
FSDir_Close(p_dir, &fs_err);
return (fs_dir_entry_cnt);
}
/*
*********************************************************************************************************
* PlayList_GetFileName()
*
* Description : Retrieve the song file name.
*
* Argument(s) : song_ix Index of song.
*
* p_song_name Pointer to destination string to receive song file name.
*
* Return(s) : DEF_OK, if song name retrieved successfully.
* DEF_FAIL, otherwise.
*
* Caller(s) : AudioUI_Task(),
* AudioMgr_Task().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_BOOLEAN PlayList_GetFileName (CPU_INT16U song_ix,
CPU_CHAR *p_song_name)
{
AUDIO_INFO *p_info;
p_info = PlayList_GetFileInfo(song_ix, DEF_FALSE);
if (p_info == (AUDIO_INFO *)0) {
p_song_name[0] = ASCII_CHAR_NUL;
return (DEF_FAIL);
}
Str_Copy_N(p_song_name,
p_info->Name,
APP_SONG_NAME_SIZE_MAX);
p_song_name[APP_SONG_NAME_SIZE_MAX] = ASCII_CHAR_NUL;
return (DEF_OK);
}
/*
*********************************************************************************************************
* PlayList_GetFileInfo()
*
* Description : Retrieve the song file information.
*
* Argument(s) : song_ix Index of song.
*
* force_refresh Force cache refresh.
*
* Return(s) : Pointer to audio information structure, if successful.
* Pointer to NULL, otherwise.
*
* Caller(s) : AudioUI_Task(),
* AudioMgr_Task().
*
* Note(s) : (1) If 'song_ix' is outside cache limits, cache table is updated.
*********************************************************************************************************
*/
static AUDIO_INFO *PlayList_GetFileInfo (CPU_INT16U song_ix,
CPU_BOOLEAN force_refresh)
{
FS_DIR *p_dir;
FS_DIR_ENTRY fs_dir_entry;
CPU_INT16U fs_dir_entry_cnt;
CPU_SIZE_T fs_file_name_len;
CPU_CHAR fs_file_ext[4 + 1];
CPU_CHAR *p_file_ext_cmp;
CPU_INT16U song_cache_ix;
FS_ERR fs_err;
FS_ERR fs_dir_err;
CPU_INT16U mid;
CPU_BOOLEAN loop;
CPU_INT32U samplerate;
if ((force_refresh == DEF_TRUE) ||
(song_ix < AudioSongInfoCacheStart) ||
(song_ix >= (AudioSongInfoCacheStart + APP_SONG_CACHE_NBR))) {
p_dir = FSDir_Open((CPU_CHAR *)APP_AUDIO_FS_FOLDER,
(FS_ERR *)&fs_dir_err);
if (fs_dir_err != FS_ERR_NONE) {
LCD_Err("SD Card Read Failed",
"FSDir_Open Err");
return ((AUDIO_INFO *)0);
}
mid = (APP_SONG_CACHE_NBR - 1) / 2;
if (song_ix > mid) {
AudioSongInfoCacheStart = song_ix - mid;
} else {
AudioSongInfoCacheStart = 1;
}
loop = DEF_TRUE;
fs_dir_entry_cnt = 0u;
do {
FSDir_Rd(p_dir, &fs_dir_entry, &fs_err);
if (fs_err != FS_ERR_NONE) {
continue;
}
fs_file_name_len = Str_Len_N(fs_dir_entry.Name,
APP_SONG_NAME_SIZE_MAX + 1);
if ((fs_file_name_len > APP_SONG_NAME_SIZE_MAX) ||
(fs_file_name_len < APP_SONG_NAME_SIZE_MIN)) {
continue;
}
p_file_ext_cmp = FSUtil_GetFileExt(fs_file_ext, fs_dir_entry.Name, 4);
/* Check if the entry is a "wav" file */
if (Str_CmpIgnoreCase_N(p_file_ext_cmp, "wav", 4) == 0) {
/* Skip entries until song_lst_ix. */
fs_dir_entry_cnt++;
if (fs_dir_entry_cnt >= AudioSongInfoCacheStart) {
song_cache_ix = fs_dir_entry_cnt - AudioSongInfoCacheStart;
AudioWave_GetInfo(fs_dir_entry.Name,
&AudioSongInfoCache[song_cache_ix]);
/* Abort cache if refreshed all entries. */
if (song_cache_ix >= (APP_SONG_CACHE_NBR - 1)) {
loop = DEF_FALSE;
}
}
}
/* Check if the entry is a "dat" file */
if (Str_CmpIgnoreCase_N(p_file_ext_cmp, "dat", 4) == 0) {
samplerate = AudioADPCM_GetSamplerate(fs_dir_entry.Name);
if (samplerate == 0) {
continue;
}
/* Skip entries until song_lst_ix. */
fs_dir_entry_cnt++;
if (fs_dir_entry_cnt >= AudioSongInfoCacheStart) {
song_cache_ix = fs_dir_entry_cnt - AudioSongInfoCacheStart;
AudioADPCM_GetInfo(fs_dir_entry.Name,
&AudioSongInfoCache[song_cache_ix]);
/* Abort cache if refreshed all entries. */
if (song_cache_ix >= (APP_SONG_CACHE_NBR - 1)) {
loop = DEF_FALSE;
}
}
}
} while ((fs_err == FS_ERR_NONE) &&
(loop == DEF_TRUE));
FSDir_Close(p_dir, &fs_dir_err);
if ((fs_err != FS_ERR_NONE) &&
(fs_err != FS_ERR_EOF )) {
LCD_Err("SD Card Read Failed",
"FSDir_Rd Err");
return ((AUDIO_INFO *)0);
}
}
return (&AudioSongInfoCache[song_ix - AudioSongInfoCacheStart]);
}
/*
*********************************************************************************************************
* AudioADPCM_GetSamplerate()
*
* Description : Retrieve sample rate from ADPCM file name.
*
* Argument(s) : p_name Pointer to song file name.
*
* Return(s) : Sample rate of ADPCM file, if successful.
* 0 , otherwise.
*
* Caller(s) : PlayList_GetFileName(),
* AudioADPCM_GetInfo().
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_INT32U AudioADPCM_GetSamplerate (const CPU_CHAR *p_name)
{
CPU_CHAR *p_samplerate;
CPU_INT32U samplerate;
p_samplerate = Str_Char_Last(p_name, '-');
if (p_samplerate == (CPU_CHAR *)0) {
return (0);
}
samplerate = Str_ParseNbr_Int32U( &p_samplerate[1],
(CPU_CHAR **)0,
DEF_NBR_BASE_DEC);
switch (samplerate) {
case 8000u:
case 11025u:
case 16000u:
case 22050u:
case 24000u:
case 32000u:
case 44100u:
case 48000u:
return (samplerate);
default:
return (0);
}
}
/*
*********************************************************************************************************
* AudioADPCM_GetInfo()
*
* Description : Retrieve format information from ADPCM song.
*
* Argument(s) : p_name Index of song.
*
* p_info Pointer to audio information structure.
*
* Return(s) : none.
*
* Caller(s) : PlayList_GetFileName().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioADPCM_GetInfo (const CPU_CHAR *p_name,
AUDIO_INFO *p_info)
{
/* Allow space for directory name. */
CPU_CHAR fullname[APP_SONG_NAME_SIZE_MAX + sizeof(APP_AUDIO_FS_FOLDER) + 1];
FS_ENTRY_INFO fs_info;
FS_FILE *p_file;
CPU_INT32U samplerate;
FS_ERR fs_err;
samplerate = AudioADPCM_GetSamplerate(p_name);
Str_Copy_N(p_info->Name,
p_name,
APP_SONG_NAME_SIZE_MAX);
p_info->Name[APP_SONG_NAME_SIZE_MAX] = ASCII_CHAR_NUL;
p_info->Valid = DEF_FALSE;
p_info->NbrCh = 1u;
p_info->SamplesPerSec = samplerate;
p_info->AvgBytesPerSec = (samplerate * 4u) / DEF_OCTET_NBR_BITS;
p_info->BitsPerSample = 4u;
p_info->TimeLen = 0u;
if (samplerate > 0u) {
Str_Copy(fullname, APP_AUDIO_FS_FOLDER);
Str_Cat(fullname, p_info->Name);
p_file = FSFile_Open(fullname,
FS_FILE_ACCESS_MODE_RD |
FS_FILE_ACCESS_MODE_CACHED,
&fs_err);
if (fs_err != FS_ERR_NONE) {
return;
}
FSFile_Query(p_file, &fs_info, &fs_err);
if (fs_err == FS_ERR_NONE) {
p_info->Valid = DEF_TRUE;
p_info->TimeLen = (fs_info.Size + p_info->AvgBytesPerSec / 2u) / p_info->AvgBytesPerSec;
}
FSFile_Close(p_file, &fs_err);
}
}
/*
*********************************************************************************************************
* AudioWave_GetInfo()
*
* Description : Retrieve format information from wave song.
*
* Argument(s) : p_name Index of song.
*
* p_info Pointer to audio information structure.
*
* Return(s) : none.
*
* Caller(s) : PlayList_GetFileName().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AudioWave_GetInfo (const CPU_CHAR *p_name,
AUDIO_INFO *p_info)
{
CPU_CHAR fullname[APP_SONG_NAME_SIZE_MAX + 1 + 12]; /* Add space for directory name. */
FS_FILE *p_file;
CPU_SIZE_T octets_rd;
CPU_SIZE_T len;
RIFF_FMT riff_fmt;
RIFF_CHUNK riff_chunk;
PCM_WAVE_FMT pcm_wave_fmt;
FS_ERR fs_err;
CPU_BOOLEAN song_end;
Str_Copy_N(p_info->Name,
p_name,
APP_SONG_NAME_SIZE_MAX);
p_info->Name[APP_SONG_NAME_SIZE_MAX] = ASCII_CHAR_NUL;
p_info->Valid = DEF_FALSE;
p_info->NbrCh = 0u;
p_info->SamplesPerSec = 0u;
p_info->AvgBytesPerSec = 0u;
p_info->BitsPerSample = 0u;
p_info->TimeLen = 0u;
Str_Copy(fullname, APP_AUDIO_FS_FOLDER);
Str_Cat(fullname, p_info->Name);
p_file = FSFile_Open(fullname,
FS_FILE_ACCESS_MODE_RD |
FS_FILE_ACCESS_MODE_CACHED,
&fs_err);
if (fs_err != FS_ERR_NONE) {
return;
}
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *)&riff_fmt,
(CPU_SIZE_T) sizeof(RIFF_FMT),
(FS_ERR *)&fs_err);
if((fs_err != FS_ERR_NONE) ||
(octets_rd != sizeof(RIFF_FMT)) ||
(riff_fmt.Chunk.ID != RIFF_CHUNK_ID) ||
(riff_fmt.Fmt != RIFF_CHUNK_TYPE_WAVE)) {
FSFile_Close(p_file, &fs_err);
return;
}
song_end = DEF_NO;
while (song_end == DEF_NO) {
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *)&riff_chunk,
(CPU_SIZE_T) sizeof(RIFF_CHUNK),
(FS_ERR *)&fs_err);
if ((fs_err != FS_ERR_NONE) ||
(octets_rd != sizeof(RIFF_CHUNK))) {
song_end = DEF_YES;
continue;
}
switch (riff_chunk.ID) {
case RIFF_WAVE_CHUNK_ID_FMT:
Mem_Clr(&pcm_wave_fmt, sizeof(PCM_WAVE_FMT));
len = DEF_MIN(riff_chunk.Size, sizeof(PCM_WAVE_FMT));
octets_rd = FSFile_Rd((FS_FILE *) p_file,
(void *)&pcm_wave_fmt,
(CPU_SIZE_T) len,
(FS_ERR *)&fs_err);
if ((fs_err != FS_ERR_NONE) ||
(octets_rd != len)) {
song_end = DEF_YES;
continue;
}
if (pcm_wave_fmt.FmtTag != RIFF_WAVE_FMT_TAG_PCM) {
song_end = DEF_YES;
continue;
}
/* Skip additional fmt fields. */
if (riff_chunk.Size > sizeof(PCM_WAVE_FMT)) {
len = riff_chunk.Size - sizeof(PCM_WAVE_FMT);
FSFile_PosSet((FS_FILE *) p_file,
(FS_FILE_OFFSET) len,
(FS_STATE ) FS_FILE_ORIGIN_CUR,
(FS_ERR *)&fs_err);
if (fs_err != FS_ERR_NONE) {
song_end = DEF_TRUE;
continue;
}
}
switch (pcm_wave_fmt.BitsPerSample) {
case 8u:
case 16u:
break;
default:
song_end = DEF_YES;
continue;
}
break;
case RIFF_WAVE_CHUNK_ID_DATA:
p_info->Valid = DEF_TRUE;
p_info->NbrCh = pcm_wave_fmt.NbrCh;
p_info->SamplesPerSec = pcm_wave_fmt.SamplesPerSec;
p_info->AvgBytesPerSec = pcm_wave_fmt.AvgBytesPerSec;
p_info->BitsPerSample = pcm_wave_fmt.BitsPerSample;
p_info->TimeLen = (riff_chunk.Size + pcm_wave_fmt.AvgBytesPerSec / 2u) / pcm_wave_fmt.AvgBytesPerSec;
song_end = DEF_TRUE;
break;
default:
FSFile_PosSet((FS_FILE *) p_file,
(FS_FILE_OFFSET) riff_chunk.Size,
(FS_STATE ) FS_FILE_ORIGIN_CUR,
(FS_ERR *)&fs_err);
if (fs_err != FS_ERR_NONE) {
song_end = DEF_TRUE;
continue;
}
break;
}
}
FSFile_Close(p_file, &fs_err);
}
/*
*********************************************************************************************************
* FSUtil_GetFileName()
*
* Description : Retrieve file name from full name.
*
* Argument(s) : p_name Pointer to destination string to receive file name.
*
* p_fullname Pointer to source string of file full name (see Note #1).
*
* len_max Maximum number of characters to limit file name (see Note #2).
*
* Return(s) : none.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : (1) Full name is the concatenation of file name, dot, and file extension.
*
* (2) File name terminates when :
*
* (a) Destination/Source string pointer(s) are passed NULL pointers.
* (1) NULL pointer returned.
*
* (b) Destination/Source string pointer(s) point to NULL.
* (1) String buffer(s) overlap with NULL address; NULL pointer returned.
*
* (c) Source string's terminating NULL character found.
* (1) Entire source string copied into destination string buffer.
*
* (d) Last dot '.' character found on source string before 'len_max'.
*
* (e) 'len_max' number of characters copied.
* (1) 'len_max' number of characters SHALL NOT include the terminating NULL
* character.
* (2) Null copies allowed (i.e. zero-length copies).
* (A) No string copy performed; destination string returned.
*
* (3) NULL character inserted into 'len_max' index of destination string to guarantee
* properly NULL string termination.
*********************************************************************************************************
*/
static CPU_CHAR *FSUtil_GetFileName ( CPU_CHAR *p_name,
const CPU_CHAR *p_fullname,
CPU_SIZE_T len_max)
{
const CPU_CHAR *p_last_dot;
CPU_CHAR *p_output;
CPU_SIZE_T len_name;
CPU_SIZE_T len_ext;
CPU_SIZE_T len;
p_last_dot = Str_Char_Last(p_fullname, '.');
if (p_last_dot == (void *)0) {
len_name = len_max;
} else {
len_ext = Str_Len(p_last_dot);
len = Str_Len(p_fullname);
len_name = DEF_MIN(len - len_ext, len_max);
}
p_output = Str_Copy_N(p_name, p_fullname, len_name);
if (p_name != (CPU_CHAR *)0) {
p_name[len_name] = ASCII_CHAR_NUL;
}
return (p_output);
}
/*
*********************************************************************************************************
* FSUtil_GetFileExt()
*
* Description : Retrieve file extension from full name.
*
* Argument(s) : p_ext Pointer to destination string to receive file extension.
*
* p_fullname Pointer to source string of file full name (see Note #1).
*
* len_max Maximum number of characters to limit file name (see Note #2).
*
* Return(s) : none.
*
* Caller(s) : AudioMgr_Task(),
* PlayList_GetNbrFiles(),
* PlayList_GetFileName().
*
* Note(s) : (1) Full name is the concatenation of file name, dot, and file extension.
*
* (2) File extension terminates when :
*
* (a) Destination/Source string pointer(s) are passed NULL pointers.
* (1) NULL pointer returned.
*
* (b) Destination/Source string pointer(s) point to NULL.
* (1) String buffer(s) overlap with NULL address; NULL pointer returned.
*
* (c) Source string's terminating NULL character found before finding last '.'
* character.
*
* (d) 'len_max' number of characters copied.
* (1) 'len_max' number of characters SHALL NOT include the terminating NULL
* character.
* (2) Null copies allowed (i.e. zero-length copies).
* (A) No string copy performed; destination string returned.
*
* (3) NULL character inserted into 'len_max' index of destination string to guarantee
* properly NULL string termination.
*********************************************************************************************************
*/
static CPU_CHAR *FSUtil_GetFileExt ( CPU_CHAR *p_ext,
const CPU_CHAR *p_fullname,
CPU_SIZE_T len_max)
{
const CPU_CHAR *p_last_dot;
CPU_CHAR *p_output;
CPU_SIZE_T len_ext;
p_last_dot = Str_Char_Last(p_fullname, '.');
if (p_last_dot == (void *)0) {
p_output = Str_Copy(p_ext, "");
} else {
len_ext = Str_Len_N(&p_last_dot[1], len_max);
len_ext++;
p_output = Str_Copy_N(p_ext, &p_last_dot[1], len_ext);
p_ext[len_max] = ASCII_CHAR_NUL;
}
return (p_output);
}
/*
*********************************************************************************************************
* LCD_Clr()
*
* Description : Clear graph LCD.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : AppAudio_Init(),
* AudioUI_Task().
*
* Note(s) : (1) Two header lines are not cleared.
*********************************************************************************************************
*/
static void LCD_Clr (void)
{
CPU_INT08U line;
for (line = 2u; line <= 7u; line++) {
BSP_GraphLCD_ClrLine(line);
}
}
/*
*********************************************************************************************************
* LCD_Msg()
*
* Description : Display message on graph LCD.
*
* Argument(s) : msg_line_1 First line of message.
*
* msg_line_2 Second line of message.
*
* Return(s) : none.
*
* Caller(s) : AudioUI_Task().
*
* Note(s) : (1) Messages are displayed on lines 3 and 4.
*
* (a) Each message line is centered.
*
* (3) Blank/space line 5 to separate from error messages.
*********************************************************************************************************
*/
static void LCD_Msg (const CPU_CHAR *msg_line_1,
const CPU_CHAR *msg_line_2)
{
CPU_SIZE_T len;
CPU_INT08U col;
BSP_GraphLCD_ClrLine(2u);
BSP_GraphLCD_ClrLine(3u);
BSP_GraphLCD_ClrLine(4u);
BSP_GraphLCD_ClrLine(5u);
if (msg_line_1 != (CPU_CHAR *)0) {
len = Str_Len(msg_line_1);
if (len > 19u) {
col = 0u;
} else {
col = (19u - len) / 2u;
}
BSP_GraphLCD_StringPosLen(3u, col, msg_line_1, 19u);
}
if (msg_line_2 != (CPU_CHAR *)0) {
len = Str_Len(msg_line_2);
if (len > 19u) {
col = 0u;
} else {
col = (19u - len) / 2u;
}
BSP_GraphLCD_StringPosLen(4u, col, msg_line_2, 19u);
}
}
/*
*********************************************************************************************************
* LCD_Err()
*
* Description : Display error message on graph LCD.
*
* Argument(s) : msg_line_1 First line of error message.
*
* msg_line_2 Second line of error message.
*
* Return(s) : none.
*
* Caller(s) : AudioUI_Task(),
* AudioMgr_Task(),
* AudioPlayback_Wave(),
* PlayList_GetFileName().
*
* Note(s) : (1) Messages are displayed on lines 3 and 4.
*
* (a) Each message line is centered.
*
* (3) Blank/space line 5 to separate from error messages.
*********************************************************************************************************
*/
static void LCD_Err (const CPU_CHAR *msg_line_1,
const CPU_CHAR *msg_line_2)
{
CPU_SIZE_T len;
CPU_INT08U col;
BSP_GraphLCD_ClrLine(6u);
BSP_GraphLCD_ClrLine(7u);
if (msg_line_1 != (CPU_CHAR *)0) {
len = Str_Len(msg_line_1);
if (len > 19u) {
col = 0u;
} else {
col = (19u - len) / 2u;
}
BSP_GraphLCD_StringPosLen(6u, col, msg_line_1, 19u);
}
if (msg_line_2 != (CPU_CHAR *)0) {
len = Str_Len(msg_line_2);
if (len > 19u) {
col = 0u;
} else {
col = (19u - len) / 2u;
}
BSP_GraphLCD_StringPosLen(7u, col, msg_line_2, 19u);
}
}
/*
*********************************************************************************************************
* ADC_TmrInit()
*
* Description : Initialize MTU0 to trigger ADC conversions.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Note(s) : (1) MTU0 operate in normal mode.
*********************************************************************************************************
*/
static void ADC_TmrInit (void)
{
CPU_INT32U freq;
CPU_INT16U per;
MSTP(MTU0) = 0u; /* Start MTU0. */
MTU0.TCR.BIT.TPSC = 3u; /* 3 = PCLK / 64. */
MTU0.TCR.BIT.CCLR = 1u; /* 1 = TCNT cleared by TGRA compare match */
MTU0.TMDR.BIT.MD = 0u; /* 0 = PWM normal operation */
freq = BSP_CPU_PerClkFreq();
freq /= 64u;
per = freq / 50u;
MTU0.TGRA = per - 1u;
MTU0.TIER.BIT.TTGE = 1u; /* Enable ADC converter start request */
MTUA.TSTR.BIT.CST0 = 1u; /* Enable MTU0. */
}
/*
*********************************************************************************************************
* ADC_Init()
*
* Description : Initialize ADC1 to read POT1.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Note(s) : (1) AN4 is input from POT1.
*********************************************************************************************************
*/
static void ADC_Init (void)
{
MSTP(S12AD) = 0u; /* Start S12AD 12-bit ADC. */
S12AD.ADCSR.BIT.ADST = 0u; /* Stop ADC */
S12AD.ADCSR.BIT.ADCS = 0u; /* Single-scan mode */
S12AD.ADCSR.BIT.ADIE = 0u; /* Disable conversion interrupt */
S12AD.ADCSR.BIT.TRGE = 1u; /* Trigger by external source */
S12AD.ADCSR.BIT.EXTRG = 0u; /* Trigger by MTU2 or MTU2S */
S12AD.ADANS.BIT.ANS = DEF_BIT_04; /* Enable AN4 channel */
S12AD.ADSTRGR.BIT.ADSTRS = 1u; /* Trigger by MTU0 compare match A */
S12AD.ADCER.BIT.ADRFMT = 1u; /* Left-aligned data */
PORT4.ICR.BIT.B4 = 1u; /* P44 input routed to peripheral */
}
/*
*********************************************************************************************************
* ADC_PotRd()
*
* Description : Read ADC value from POT1.
*
* Argument(s) : none.
*
* Return(s) : Left-aligned potentiometer value.
*
* Note(s) : none.
*********************************************************************************************************
*/
static CPU_INT16U ADC_PotRd (void)
{
return (S12AD.ADDRE);
}
/*
*********************************************************************************************************
* SSM2377_Init()
*
* Description : Initialize SSM2377 audio amplifier.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
#if (AUDIO_CFG_SSM2377_EN > 0u)
static void SSM2377_Init (void)
{
SSM2377_En(DEF_DISABLED);
SSM2377_Gain(DEF_NO);
AppProbe_AudioLowGain = DEF_YES;
PORTA.DDR.BYTE |= DEF_BIT_01; /* PA: Gain (PA1) set as output. */
PORTA.DDR.BYTE |= DEF_BIT_02; /* PA: Shutdown (PA2) set as output. */
SSM2377_En(DEF_ENABLED);
}
#endif
/*
*********************************************************************************************************
* SSM2377_En()
*
* Description : Enable SSM2377 audio amplifier.
*
* Argument(s) : en Enable state.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : 1) Shutdown pin connected to PA2.
*********************************************************************************************************
*/
#if (AUDIO_CFG_SSM2377_EN > 0u)
static void SSM2377_En (CPU_BOOLEAN en)
{
if (en == DEF_ENABLED) {
PORTA.DR.BYTE |= DEF_BIT_02;
} else {
PORTA.DR.BYTE &= ~DEF_BIT_02;
}
}
#endif
/*
*********************************************************************************************************
* SSM2377_Gain()
*
* Description : Set low or high gain for the SSM2377 audio amplifier.
*
* Argument(s) : high High gain state.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : 1) Gain pin connected to PA1.
*********************************************************************************************************
*/
#if (AUDIO_CFG_SSM2377_EN > 0u)
static void SSM2377_Gain (CPU_BOOLEAN high)
{
if (high == DEF_YES) {
PORTA.DR.BYTE &= ~DEF_BIT_01; /* High Gain: 12dB. */
} else {
PORTA.DR.BYTE |= DEF_BIT_01; /* Low Gain: 6dB. */
}
}
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex2/app.c
|
<filename>uCOS-III-Ex2/app.c
/*
*********************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP.C
* By : FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#define APP_ACCEL_HYST 10
#define APP_ACCEL_NEG(val,ref) (val < (ref - APP_ACCEL_HYST))
#define APP_ACCEL_POS(val,ref) (val > (ref + APP_ACCEL_HYST))
#define APP_ACCEL_ZERO(val,ref) ((val > (ref - APP_ACCEL_HYST)) && \
(val < (ref + APP_ACCEL_HYST)))
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_TCB AppTaskStartTCB;
static OS_TCB AppAccelTaskTCB;
static OS_TCB AppTempTaskTCB;
static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static CPU_STK AppAccelTaskStk[ACCEL_TASK_STK_SIZE];
static CPU_STK AppTempTaskStk[TEMPERATURE_TASK_STK_SIZE];
static CPU_BOOLEAN AppTCPIP_Cfg = DEF_FALSE;
volatile CPU_INT08U AppCloudControlLedOn = 1;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppAccelTask (void *p_arg);
static void AppTempTask (void *p_arg);
static void AppGraphLCD_Hdr(void);
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppTCPIP_Init (NET_ERR *perr);
#endif
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
void AppProbe_Init (void);
#endif
void AppCloud_Init (CPU_BOOLEAN disableStatus);
#define EX_LED_ON(a) {if (AppCloudControlLedOn) LED_On(a); else LED_Off(a);}
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
extern volatile CPU_INT16S BSP_Accel_X_Zero;
extern volatile CPU_INT16S BSP_Accel_Y_Zero;
extern volatile CPU_INT16S BSP_Accel_Z_Zero;
CPU_INT08U AppQuadrant = 1;
CPU_FP32 AppDegrees = 0.0f;
CPU_INT32U AppMagnitude = 0;
CPU_FP32 AppTemp_C = 0.0f;
CPU_FP32 AppTemp_F = 0.0f;
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main (void)
{
OS_ERR err;
CPU_IntDis(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
App_OS_SetAllHooks();
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) 0,
(OS_PRIO ) APP_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while (1) {
;
}
return (0);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
NET_ERR net_err;
#endif
(void)&p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */
#if (OS_CFG_STAT_TASK_EN > 0u)
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
AppProbe_Init(); /* Initialize uC/Probe modules */
#endif
OSTaskCreate((OS_TCB *)&AppAccelTaskTCB, /* Create the accelerometer task */
(CPU_CHAR *)"Accel Task",
(OS_TASK_PTR ) AppAccelTask,
(void *) 0,
(OS_PRIO ) ACCEL_TASK_PRIO,
(CPU_STK *)&AppAccelTaskStk[0],
(CPU_STK_SIZE) ACCEL_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) ACCEL_TASK_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AppTempTaskTCB, /* Create the temperature task */
(CPU_CHAR *)"Temp Task",
(OS_TASK_PTR ) AppTempTask,
(void *) 0,
(OS_PRIO ) TEMPERATURE_TASK_PRIO,
(CPU_STK *)&AppTempTaskStk[0],
(CPU_STK_SIZE) TEMPERATURE_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) TEMPERATURE_TASK_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
BSP_GraphLCD_Init();
AppGraphLCD_Hdr();
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */
AppCloud_Init(0);
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
AppTCPIP_Cfg = DEF_TRUE;
while (DEF_ON) {
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
/*
*********************************************************************************************************
* ACCELEROMETER TASK
*
* Description : This task initialises the ADXL345 accelerometer, sets the zero points for
* the X and Y axis. It then periodically reads the current X and Y values from
* the accelerometer and calculates the inclination angle and AppMagnitude of the
* the board. Illuminates the LED corresponding to the direction the board is
* currently tilted.
*
* Arguments : p_arg is the argument passed to 'AppAccelTask()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppAccelTask (void *p_arg)
{
OS_ERR err;
CPU_FP32 angle_radians;
CPU_FP32 angle_degrees;
CPU_INT16S accel_x_axis;
CPU_INT16S accel_y_axis;
CPU_INT16S accel_z_axis;
CPU_FP32 x;
CPU_FP32 x2;
CPU_FP32 y;
CPU_FP32 y2;
CPU_FP32 sum_x2_y2;
(void)&p_arg;
angle_radians = 0.0f;
angle_degrees = 0.0f;
BSP_Accel_Init(); /* Initialize the accelerometer */
BSP_Accel_ZeroCal(); /* Calibrate the accelerometer */
LED_Off(0); /* Turn all LEDs off */
while (DEF_ON) {
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
accel_x_axis = BSP_Accel_X_AxisRd();
accel_y_axis = BSP_Accel_Y_AxisRd();
if ((APP_ACCEL_ZERO(accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_ZERO(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 5; /* Board is flat */
} else if ((APP_ACCEL_NEG (accel_y_axis, BSP_Accel_Y_Zero)) &&
(APP_ACCEL_ZERO(accel_x_axis, BSP_Accel_X_Zero))) {
AppQuadrant = 6;
} else if ((APP_ACCEL_POS (accel_y_axis, BSP_Accel_Y_Zero)) &&
(APP_ACCEL_ZERO(accel_x_axis, BSP_Accel_X_Zero))) {
AppQuadrant = 7;
} else if ((APP_ACCEL_POS (accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_ZERO(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 8;
} else if ((APP_ACCEL_NEG (accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_ZERO(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 9;
} else if ((APP_ACCEL_POS(accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_POS(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 3;
} else if ((APP_ACCEL_POS(accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_NEG(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 4;
} else if ((APP_ACCEL_NEG(accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_POS(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 2;
} else if ((APP_ACCEL_NEG(accel_x_axis, BSP_Accel_X_Zero)) &&
(APP_ACCEL_NEG(accel_y_axis, BSP_Accel_Y_Zero))) {
AppQuadrant = 1;
}
x = accel_x_axis;
y = accel_y_axis;
x -= BSP_Accel_X_Zero; /* Normalize */
y -= BSP_Accel_Y_Zero;
x2 = x * x;
y2 = y * y;
sum_x2_y2 = x2 + y2;
AppMagnitude = sqrt(sum_x2_y2 / 2.0f);
if ((fabs(x) > 0.5f) && /* Both axis are greater than zero. */
(fabs(y) > 0.5f)) {
angle_radians = atan2(fabs(x), fabs(y));
angle_degrees = (angle_radians * 180.0f) / 3.1415926535897932f;
}
if (AppQuadrant == 5) {
AppDegrees = 0.0f;
if (AppTCPIP_Cfg == DEF_TRUE) {
EX_LED_ON( 4); /* Turn on all LEDs when the board is flat and ... */
EX_LED_ON( 5); /* ... TCP-IP initialization is complete. */
EX_LED_ON( 6);
EX_LED_ON( 7);
EX_LED_ON( 8);
EX_LED_ON( 9);
EX_LED_ON(10);
EX_LED_ON(11);
EX_LED_ON(12);
EX_LED_ON(13);
EX_LED_ON(14);
EX_LED_ON(15);
} else {
EX_LED_ON ( 4); /* Turn on half of the LEDs to show that TCP-IP ... */
LED_Off( 5); /* ... initialization is NOT yet complete. */
EX_LED_ON ( 6);
LED_Off( 7);
EX_LED_ON ( 8);
LED_Off( 9);
EX_LED_ON (10);
LED_Off(11);
EX_LED_ON (12);
LED_Off(13);
EX_LED_ON (14);
LED_Off(15);
}
} else {
LED_Off(0); /* Turn off all LEDs */
switch (AppQuadrant) {
case 1:
AppDegrees = angle_degrees;
if (angle_degrees < 30.0f) {
EX_LED_ON(4);
} else if (angle_degrees < 60.0f) {
EX_LED_ON(5);
} else {
EX_LED_ON(6);
}
break;
case 2:
AppDegrees = 180.0f - angle_degrees;
if (angle_degrees < 30.0f) {
EX_LED_ON(9);
} else if (angle_degrees < 60.0f) {
EX_LED_ON(8);
} else {
EX_LED_ON(7);
}
break;
case 3:
AppDegrees = angle_degrees + 180.0f;
if (angle_degrees < 30.0f) {
EX_LED_ON(10);
} else if( angle_degrees < 60.0f) {
EX_LED_ON(11);
} else {
EX_LED_ON(12);
}
break;
case 4:
AppDegrees = 360.0f - angle_degrees;
if (angle_degrees < 30.0f) {
EX_LED_ON(15);
} else if (angle_degrees < 60.0f) {
EX_LED_ON(14);
} else {
EX_LED_ON(13);
}
break;
case 6:
AppDegrees = 0.0f;
EX_LED_ON(4);
break;
case 7:
AppDegrees = 180.0f;
EX_LED_ON(10);
break;
case 8:
AppDegrees = 270.0f;
EX_LED_ON(13);
break;
case 9:
AppDegrees = 90.0f;
EX_LED_ON(7);
break;
}
}
}
}
/*
*********************************************************************************************************
* TEMPERATURE SENSOR TASK
*
* Description : This task initialises the ADT7420 temperature sensor.
* It then periodically reads the current temperature and updates global
* variables AppTemp_C and AppTemp_F.
* The temperature sensor is connected to the micro via I2C as is the accelerometer.
* Having tasks accessing both demonstrates the use of a mutex in the I2C driver.
*
* Arguments : p_arg is the argument passed to 'AppAccelTask()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTempTask (void *p_arg)
{
OS_ERR err;
CPU_FP32 temp_c;
(void)&p_arg;
BSP_Temp_Init(); /* Initialize temperature sensor. */
while (DEF_ON) {
OSTimeDlyHMSM(0u, 0u, 0u, 10u,
OS_OPT_TIME_HMSM_STRICT,
&err);
temp_c = BSP_Temp_Rd();
AppTemp_C = temp_c;
AppTemp_F = (AppTemp_C * 9.0f / 5.0f) + 32.0f;
}
}
/*
*********************************************************************************************************
* AppGraphLCD_Hdr()
*********************************************************************************************************
*/
static void AppGraphLCD_Hdr (void)
{
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_LARGE);
BSP_GraphLCD_StringPos(0, 4, "Micrium");
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SMALL);
BSP_GraphLCD_StringPos(1, 5, "uC/OS-III");
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
BSP_GraphLCD_StringPos(2, 5, "uC/TCP-IP");
#endif
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib-Ex6/fs_cfg.h
|
<reponame>nbarjolin/micrium_gnurx_cloud
/*
*********************************************************************************************************
* uC/FS V4
* The Embedded File System
*
* (c) Copyright 2008-2010; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/FS is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* FILE SYSTEM CONFIGURATION FILE
*
* TEMPLATE
*
* Filename : fs_cfg.h
* Version : V4.04
* Programmer(s) : FBJ
* BAN
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* FILE SYSTEM CONFIGURATION
*
* Note(s) : (1) Configure FS_CFG_SYS_DRV_SEL to select file system driver inclusion :
* (a) When FS_SYS_DRV_SEL_FAT, the FAT file system driver will be used.
*
* (2) Configure FS_CFG_CACHE_EN to enable/disable the cache support :
* (a) When ENABLED, cache functionality will be available.
* (b) When DISABLED, cache functionality will be NOT available.
*
* (3) Configure FS_CFG_API_EN to enable/disable presence of POSIX-compatible API :
* (a) When ENABLED, POSIX-compatible API will be present.
* (b) When DISABLED, POSIX-compatible API will NOT be present.
*
* (4) Configure FS_CFG_DIR_EN to enable/disable presence of directory access module :
* (a) When ENABLED, directory access module will be present.
* (b) When DISABLED, directory access module will NOT be present.
*
* (5) Configure FS_CFG_FILE_BUF_EN to enable/disable file buffer support :
* (a) When ENABLED, file read/write buffer functionality will be available.
* (b) When DISABLED, file read/write buffer functionality will NOT be available.
*
* (6) Configure FS_CFG_FILE_LOCK_EN to enable/disable file lock functionality :
* (a) When ENABLED, a file can be locked across operations.
* (b) When DISABLED, a file is only locked during an operation.
*
* (7) Configure FS_CFG_PARTITION_EN to enable/disable extended support for partitions :
* (a) When ENABLED, volumes can be opened on secondary partitions & partitions can be created.
* (b) When DISABLED, volumes cannot be opened on secondary partitions & partitions cannot be created.
*
* (8) Configure FS_CFG_WORKING_DIR_EN to enable/disable working directory support :
* (a) When ENABLED, file system operations can be performed relative to a working directory.
* (b) When DISABLED, all file system operations MUST be performed on absolute paths.
*
* (9) Configure FS_CFG_UTF8_EN to enable/disable UTF-8 support :
* (a) When ENABLED, file names may be specified in UTF-8.
* (b) When DISABLED, file names must be specified in ASCII.
*
* (10) Configure FS_CFG_RD_ONLY_EN to enable/disable file/volume/device write access :
* (a) When ENABLED, files, volumes & devices may only be read. Code for write operations
* is NOT included.
* (b) When DISABLED, files, volumes & devices may be read & written.
*
* (11) Configure FS_CFG_CONCURRENT_ENTRIES_ACCESS_EN to enable/disable file/dir concurrent access :
* (a) When ENABLED, concurrent access is allowed, and operations are more flexible.
* (b) When DISABLED, concurrent access is not allowed, and operations are safer.
*********************************************************************************************************
*/
/* Configure file system driver presence (see Note #1) :*/
#define FS_CFG_SYS_DRV_SEL FS_SYS_DRV_SEL_FAT
/* FS_SYS_DRV_SEL_FAT FAT file system driver present.*/
/* Configure POSIX API presence (see Note #3) : */
#define FS_CFG_API_EN DEF_ENABLED
/* DEF_DISABLED POSIX API NOT present. */
/* DEF_ENABLED POSIX API present. */
/* Configure cache support (see Note #2) : */
#define FS_CFG_CACHE_EN DEF_DISABLED
/* DEV_DISABLED cache NOT supported. */
/* DEV_ENABLED cache supported. */
/* Configure directory module presence (see Note #4) : */
#define FS_CFG_DIR_EN DEF_ENABLED
/* DEF_DISABLED Directory module NOT present. */
/* DEF_ENABLED Directory module present. */
/* Configure file buf support (see Note #5) : */
#define FS_CFG_FILE_BUF_EN DEF_ENABLED
/* DEF_DISABLED File data rd/wr directly from vol. */
/* DEF_ENABLED File buffer can be assigned. */
/* Configure file lock support (see Note #6) : */
#define FS_CFG_FILE_LOCK_EN DEF_DISABLED
/* DEF_DISABLED Files only locked during single op. */
/* DEF_ENABLED A file may be locked across op's. */
/* Configure partition support (see Note #7) : */
#define FS_CFG_PARTITION_EN DEF_DISABLED
/* DEF_DISABLED Partition creation NOT supported. */
/* DEF_ENABLED Partition creation supported. */
/* Configure read-only operation (see Note #10) : */
#define FS_CFG_RD_ONLY_EN DEF_DISABLED
/* DEF_DISABLED Only read operations may be done. */
/* DEF_ENABLED Read & write operations may be done.*/
/* Configure UTF8 support (see Note #9) : */
#define FS_CFG_UTF8_EN DEF_DISABLED
/* DEF_DISABLED File names specified in ASCII. */
/* DEF_ENABLED File names specified in UTF-8. */
/* Config concurrent access to entries (see Note #11) : */
#define FS_CFG_CONCURRENT_ENTRIES_ACCESS_EN DEF_DISABLED
/* DEF_DISABLED Concurrent access NOT allowed. */
/* DEF_ENABLED Concurrent access allowed */
/* Configure working directory support (see Note #8) : */
#define FS_CFG_WORKING_DIR_EN DEF_DISABLED
/* DEF_DISABLED Working directory NOT supported. */
/* DEF_ENABLED Working directory supported. */
/*
*********************************************************************************************************
* FILE SYSTEM NAME RESTRICTION CONFIGURATION
*
* Note(s) : (1) Configure FS_CFG_MAX_PATH_NAME_LEN with the desired maximum path name length.
* (2) Configure FS_CFG_MAX_FILE_NAME_LEN with the desired maximum file name length.
* (3) Configure FS_CFG_MAX_VOL_NAME_LEN with the desired maximum volume name length.
*
* A full file name is composed of an explicit volume name (optionally) & a path name; the
* characters after the last non-final path separator character ('\') are the file name :
*
* | |
* |---------------------- FULL NAME LENGTH --------------------|
* | |
*
* | |
* |----------------- PATH NAME LENGTH ----------------|
* | |
*
* myvolume:\MyDir0\MyDir1\MyDir2\my_very_very_long_file_name.txt
*
* | | | |
* |---o---| |------ FILE NAME LENGTH -----|
* | | | | |
* |
* ------ VOLUME NAME LENGTH
*
* The constant 'FS_CFG_MAX_FULL_NAME_LEN' is defined in 'fs_cfg_fs.h' to describe the
* maximum full name length, as shown in this diagram.
*
*
* (4) Configure FS_CFG_MAX_DEV_DRV_NAME_LEN with the desired maximum device driver name length.
* (5) Configure FS_CFG_MAX_DEV_NAME_LEN with the desired maximum device name length.
*
* A device name is composed of a device driver name, a colon, an integer (the unit number)
* and a final colon :
*
* ------------ DEVICE NAME LENGTH
* |
* | | |
* |---o---|
* | |
* sdcard:0:
* | |
* |-o--|
* | | |
* |
* -------------- DEVICE DRIVER NAME LENGTH
*
*
* Each of these maximum name length configurations specifies the maximum string length
* WITHOUT the NULL character. Consequently, a buffer which holds one of these names
* must be one character longer than the define value.
*********************************************************************************************************
*/
/* Configure maximum device name length (see Note #5). */
#define FS_CFG_MAX_DEV_NAME_LEN 15u
/* Configure maximum device driver name length ... */
/* ... (see Note #4). */
#define FS_CFG_MAX_DEV_DRV_NAME_LEN 10u
/* Configure maximum file name length (see Note #2). */
#define FS_CFG_MAX_FILE_NAME_LEN 255u
/* Configure maximum path name length (see Note #1). */
#define FS_CFG_MAX_PATH_NAME_LEN 260u
/* Configure maximum volume name length (see Note #3). */
#define FS_CFG_MAX_VOL_NAME_LEN 10u
/*
*********************************************************************************************************
* FILE SYSTEM DEBUG CONFIGURATION
*
* Note(s) : (1) Configure FS_CFG_DBG_MEM_CLR_EN to enable/disable the file system suite from clearing
* internal data structure memory buffers; a convenient feature while debugging.
*
* (2) Configure FS_CFG_DBG_WR_VERIFY_EN to enable/disable the file system suite from verifying
* writes by reading back data; a convenient feature while debugging a driver.
*********************************************************************************************************
*/
/* Configure memory clear feature (see Note #1) : */
#define FS_CFG_DBG_MEM_CLR_EN DEF_ENABLED
/* DEF_DISABLED Data structure clears DISABLED */
/* DEF_ENABLED Data structure clears ENABLED */
/* Configure write verification feature (see Note #2) : */
#define FS_CFG_DBG_WR_VERIFY_EN DEF_DISABLED
/* DEF_DISABLED Write verification feature DISABLED */
/* DEF_ENABLED Write verification feature ENABLED */
/*
*********************************************************************************************************
* FILE SYSTEM ARGUMENT CHECK CONFIGURATION
*
* Note(s) : (1) Configure FS_ERR_CFG_ARG_CHK_EXT_EN to enable/disable the file system suite external
* argument check feature :
* (a) When ENABLED, ALL arguments received from any port interface provided by the developer
* or application are checked/validated.
* (b) When DISABLED, NO arguments received from any port interface provided by the developer
* or application are checked/validated.
*
* (2) Configure FS_ERR_CFG_ARG_CHK_DBG_EN to enable/disable the file system suite internal,
* debug argument check feature :
* (a) When ENABLED, internal arguments are checked/validated to debug the file system
* suite.
* (b) When DISABLED, NO internal arguments are checked/validated to debug the file system
* suite.
*********************************************************************************************************
*/
/* Configure external argument check feature ... */
/* ... (see Note #1) : */
#define FS_CFG_ERR_ARG_CHK_EXT_EN DEF_ENABLED
/* DEF_DISABLED Argument check DISABLED */
/* DEF_ENABLED Argument check ENABLED */
/* Configure internal argument check feature : */
/* ... (see Note #2) : */
#define FS_CFG_ERR_ARG_CHK_DBG_EN DEF_ENABLED
/* DEF_DISABLED Argument check DISABLED */
/* DEF_ENABLED Argument check ENABLED */
/*
*********************************************************************************************************
* FILE SYSTEM COUNTER MANAGEMENT CONFIGURATION
*
* Note(s) : (1) Configure FS_CTR_CFG_STAT_EN to enable/disable file system suite statistics counters.
*
* (2) Configure FS_CTR_CFG_ERR_EN to enable/disable file system suite error counters.
*********************************************************************************************************
*/
/* Configure statistics counter feature (see Note #1) : */
#define FS_CFG_CTR_STAT_EN DEF_DISABLED
/* DEF_DISABLED Stat counters DISABLED */
/* DEF_ENABLED Stat counters ENABLED */
/* Configure error counter feature (see Note #2) : */
#define FS_CFG_CTR_ERR_EN DEF_DISABLED
/* DEF_DISABLED Error counters DISABLED */
/* DEF_ENABLED Error counters ENABLED */
/*
*********************************************************************************************************
* FILE SYSTEM FAT CONFIGURATION
*
* Note(s) : (1) Configure FS_FAT_CFG_LFN_EN to enable/disable the file long file name support :
* (a) When ENABLED, long file name entries may be used.
* (b) When DISABLED, long file name entries may NOT be used.
*
* (2) Configure FS_FAT_CFG_FAT12_EN to enable/disable FAT12 support :
* (a) When ENABLED, FAT12 volumes can be accessed & formatted.
* (b) When DISABLED, FAT12 volumes can neither be accessed nor formatted.
*
* (3) Configure FS_FAT_CFG_FAT16_EN to enable/disable FAT12 support :
* (a) When ENABLED, FAT12 volumes can be accessed & formatted.
* (b) When DISABLED, FAT12 volumes can neither be accessed nor formatted.
*
* (4) Configure FS_FAT_CFG_FAT32_EN to enable/disable FAT12 support :
* (a) When ENABLED, FAT12 volumes can be accessed & formatted.
* (b) When DISABLED, FAT12 volumes can neither be accessed nor formatted.
*
* (5) Configure FS_FAT_CFG_JOURNAL_EN to enable/disable presence of journaling access module :
* (a) When ENABLED, journaling access module will be present.
* (b) When DISABLED, journaling access module will NOT be present.
*
* (6) Configure FS_FAT_CFG_VOL_CHK_EN to enable/disable volume check support :
* (a) When ENABLED, volume integrity can be checked. If enabled, FS_FAT_CFG_VOL_CHK_MAX_LEVELS
* is the maximum number of directory levels that will be checked.
* (b) When DISABLED, volume integrity can NOT be checked.
*********************************************************************************************************
*/
/* Configure Long File Name support (see Note #1) : */
#define FS_FAT_CFG_LFN_EN DEF_ENABLED
/* DEF_DISABLED LFN NOT supported. */
/* DEF_ENABLED LFN supported. */
/* Configure FAT12 support (see Note #2) : */
#define FS_FAT_CFG_FAT12_EN DEF_ENABLED
/* DEF_DISABLED FAT12 NOT supported. */
/* DEF_ENABLED FAT12 supported. */
/* Configure FAT16 support (see Note #3) : */
#define FS_FAT_CFG_FAT16_EN DEF_ENABLED
/* DEF_DISABLED FAT16 NOT supported. */
/* DEF_ENABLED FAT16 supported. */
/* Configure FAT32 support (see Note #4) : */
#define FS_FAT_CFG_FAT32_EN DEF_ENABLED
/* DEF_DISABLED FAT32 NOT supported. */
/* DEF_ENABLED FAT32 supported. */
/* Configure journaling support (see Note #5) : */
#define FS_FAT_CFG_JOURNAL_EN DEF_DISABLED
/* DEF_DISABLED Journaling NOT supported. */
/* DEF_ENABLED Journaling supported. */
/* Configure volume check support (see Note #6) : */
#define FS_FAT_CFG_VOL_CHK_EN DEF_DISABLED
/* DEF_DISABLED Volume check NOT supported. */
/* DEF_ENABLED Volume check supported. */
/* Configure max levels chk'd (see Note #6). */
#define FS_FAT_CFG_VOL_CHK_MAX_LEVELS 20u
/*
*********************************************************************************************************
* FILE SYSTEM SD/MMC DEVICE DRIVER CONFIGURATION
*
* Note(s) : (1) Configure FS_DEV_SD_SPI_CFG_CRC_EN to enable/disable CRC generation & checking for data
* writes & reads.
* (a) When enabled, a CRC will be generated for data written to the card, & the CRC of
* received data will be checked.
* (b) When disabled, no CRC will be generated for data written to the card, & the CRC of
* received data will not be checked.
*********************************************************************************************************
*/
/* Configure data CRC generation/check (see Note #2). */
#define FS_DEV_SD_SPI_CFG_CRC_EN DEF_DISABLED
/*$PAGE*/
/*
*********************************************************************************************************
* TRACING
*********************************************************************************************************
*/
#define FS_TRACE_LEVEL TRACE_LEVEL_DBG
#define FS_TRACE BSP_Ser_printf
#include <bsp_ser.h>
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex5/app_probe.c
|
<filename>uCOS-III-Ex5/app_probe.c
/*
*********************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
* Application-Defined uC/Probe Functions
*
* (c) Copyright 2010; Micrium; Weston, FL
* All Rights Reserved
*
* File : APP_PROBE.C
* By : <NAME>
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDES
*********************************************************************************************************
*/
#include <includes.h>
/*$PAGE*/
/*
*********************************************************************************************************
* INITIALIZE PROBE MODULES
*
* Description: This function initializes the modules required for uC/Probe.
*
* Arguments : none.
*
* Note(s) : none.
*********************************************************************************************************
*/
void AppProbe_Init (void)
{
#if (APP_CFG_PROBE_COM_MODULE_EN > 0)
ProbeCom_Init(); /* Initialize the uC/Probe communications module */
#if (PROBE_COM_CFG_RS232_EN > 0)
ProbeRS232_Init(PROBE_BAUD_RATE);
ProbeRS232_RxIntEn();
#endif
#if (PROBE_COM_CFG_TCPIP_EN > 0)
ProbeTCPIP_Init();
#endif
#endif
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Lib/app_cfg.h
|
/*
*********************************************************************************************************
* uC/OS-III
* APPLICATION CONFIGURATION
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP_CFG.H
* By : FGK
*********************************************************************************************************
*/
#ifndef __APP_CFG_H__
#define __APP_CFG_H__
#include <dhcp-c_cfg.h>
#include <http-s_cfg.h>
/*
*********************************************************************************************************
* ADDITIONAL uC/MODULE ENABLES
*********************************************************************************************************
*/
#define APP_CFG_TCPIP_MODULE_EN DEF_ENABLED /* DEF_ENABLED = Present, DEF_DISABLED = Not Present */
#define APP_CFG_DHCPc_MODULE_EN DEF_ENABLED
#define APP_CFG_PROBE_COM_MODULE_EN DEF_ENABLED
/*
*********************************************************************************************************
* TASK PRIORITIES
*********************************************************************************************************
*/
#define APP_TASK_START_PRIO 4u
#define BLINKY_TASK_PRIO 5u
#define ACCEL_TASK_PRIO 5u
#define TEMPERATURE_TASK_PRIO 4u
#define APP_FFT_TASK_PRIO 3u
#define NET_OS_CFG_TMR_TASK_PRIO 6u
#define NET_OS_CFG_IF_TX_DEALLOC_TASK_PRIO 7u
#define NET_OS_CFG_IF_LOOPBACK_TASK_PRIO 8u
#define NET_OS_CFG_IF_RX_TASK_PRIO 9u
#define OS_PROBE_TASK_PRIO 10u
#define CLOUD_DATA_TASK_PRIO 11u
#define HTTPs_OS_CFG_TASK_PRIO 13u
/*
*********************************************************************************************************
* TASK STACK SIZES
*********************************************************************************************************
*/
#define APP_TASK_START_STK_SIZE 256u
#define BLINKY_TASK_STK_SIZE 512u
#define ACCEL_TASK_STK_SIZE 512u
#define TEMPERATURE_TASK_STK_SIZE 512u
#define APP_FFT_TASK_STK_SIZE 320u
#define CLOUD_DATA_TASK_STK_SIZE 512u
#define NET_OS_CFG_TMR_TASK_STK_SIZE 768u
#define NET_OS_CFG_IF_TX_DEALLOC_TASK_STK_SIZE 512u
#define NET_OS_CFG_IF_LOOPBACK_TASK_STK_SIZE 512u
#define NET_OS_CFG_IF_RX_TASK_STK_SIZE 1280u
#define OS_PROBE_TASK_STK_SIZE 768u
#define HTTPs_OS_CFG_TASK_STK_SIZE 3072u
/*
*********************************************************************************************************
* uC/TCP-IP v2.0
*********************************************************************************************************
*/
#define NET_OS_CFG_IF_LOOPBACK_Q_SIZE 5u
#define NET_OS_CFG_IF_RX_Q_SIZE 14u
#define NET_OS_CFG_IF_TX_DEALLOC_Q_SIZE 10u
/*
*********************************************************************************************************
* uC/DHCPc v2.0
*********************************************************************************************************
*/
#define APP_CFG_DHCP_NBR_IF_CFGD 1u
/*
*********************************************************************************************************
* uC/LIB CONFIGURATION
*********************************************************************************************************
*/
#define LIB_MEM_CFG_OPTIMIZE_ASM_EN DEF_DISABLED
#define LIB_MEM_CFG_ARG_CHK_EXT_EN DEF_ENABLED
#define LIB_MEM_CFG_ALLOC_EN DEF_ENABLED
#define LIB_MEM_CFG_HEAP_SIZE (34 * 1024L)
/*
*********************************************************************************************************
* uC/APPs FS
*********************************************************************************************************
*/
#define APPS_FS_CFG_MAX_FILE_NAME_LEN 20u
#define APPS_FS_CFG_NBR_FILES 3u
#define APPS_FS_CFG_NBR_DIRS 1u
/*
*********************************************************************************************************
* uC/Probe plug-in for uC/OS-II CONFIGURATION
*********************************************************************************************************
*/
#define OS_PROBE_TASK 1u /* Task will be created for uC/Probe OS Plug-In */
#define OS_PROBE_HOOKS_EN 1u /* Hooks to update OS_TCB profiling members are included */
#define OS_PROBE_TMR_32_BITS 0u /* uC/Probe timer is a 32-bit timer */
#define OS_PROBE_TMR_SEL 0u /* Select timer for uC/Probe OS Plug-In timer */
#define OS_PROBE_USE_FP 1u /* uC/Probe does not use floating-point variables */
#define OS_PROBE_TASK_ID OS_PROBE_TASK_PRIO /* Current version of uC/OS-II does not use ID field */
#define PROBE_BAUD_RATE 38400u /* RS-232 baudrate used by uC/Probe */
#endif
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex3/app.c
|
/*
*********************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP.C
* By : FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
#define APP_TEST_MAX 30u
#define APP_TASK_RX_STK_SIZE APP_TASK_START_STK_SIZE
#define APP_TASK_TX_STK_SIZE APP_TASK_START_STK_SIZE
#define APP_TASK_RX_PRIO (APP_TASK_START_PRIO)
#define APP_TASK_TX_PRIO (APP_TASK_START_PRIO + 1u)
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
typedef struct app_test {
void (*Tx)(CPU_INT08U ix);
void (*Rx)(CPU_INT08U ix);
} APP_TEST;
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static CPU_BOOLEAN AppStatReset;
static OS_TCB AppTaskStartTCB;
static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static OS_TCB AppTaskRxTCB;
static CPU_STK AppTaskRxStk[APP_TASK_RX_STK_SIZE];
static OS_TCB AppTaskTxTCB;
static CPU_STK AppTaskTxStk[APP_TASK_TX_STK_SIZE];
static OS_SEM AppSem;
static OS_Q AppQ;
static OS_FLAG_GRP AppFlagGrp;
static OS_MUTEX AppMutex;
static CPU_INT08U AppTestSel;
static volatile CPU_INT16U AppTestTime_us;
static CPU_FP32 App_TS_to_us;
static CPU_TS_TMR AppTS_Delta[APP_TEST_MAX];
static CPU_TS_TMR AppTS_Start[APP_TEST_MAX];
static CPU_TS_TMR AppTS_End[APP_TEST_MAX];
volatile CPU_INT08U AppCloudControlLedOn = 1;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppGraphLCD_Hdr (void);
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppTCPIP_Init (NET_ERR *perr);
#endif
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
void AppProbe_Init (void);
#endif
static void LEDDisplaySeq0 (void);
static void LEDDisplaySeq1 (void);
static void LEDDisplaySeq2 (void);
static void LEDDisplaySeq3 (void);
static void AppTaskRx (void *p_arg);
static void AppTaskTx (void *p_arg);
static void AppTaskCreate (void);
static void AppObjCreate (void);
static void AppTestTx_Sem1 (CPU_INT08U ix);
static void AppTestRx_Sem1 (CPU_INT08U ix);
static void AppTestTx_Sem2 (CPU_INT08U ix);
static void AppTestRx_Sem2 (CPU_INT08U ix);
static void AppTestTx_TaskSem1(CPU_INT08U ix);
static void AppTestRx_TaskSem1(CPU_INT08U ix);
static void AppTestTx_TaskSem2(CPU_INT08U ix);
static void AppTestRx_TaskSem2(CPU_INT08U ix);
static void AppTestTx_Q1 (CPU_INT08U ix);
static void AppTestRx_Q1 (CPU_INT08U ix);
static void AppTestTx_Q2 (CPU_INT08U ix);
static void AppTestRx_Q2 (CPU_INT08U ix);
static void AppTestTx_TaskQ1 (CPU_INT08U ix);
static void AppTestRx_TaskQ1 (CPU_INT08U ix);
static void AppTestTx_TaskQ2 (CPU_INT08U ix);
static void AppTestRx_TaskQ2 (CPU_INT08U ix);
static void AppTestTx_Mutex1 (CPU_INT08U ix);
static void AppTestRx_Mutex1 (CPU_INT08U ix);
static void AppTestTx_Flag1 (CPU_INT08U ix);
static void AppTestRx_Flag1 (CPU_INT08U ix);
static void AppTestTx_Flag2 (CPU_INT08U ix);
static void AppTestRx_Flag2 (CPU_INT08U ix);
void AppCloud_Init (CPU_BOOLEAN disableStatus);
#define EX_LED_TOGGLE(a) {if (AppCloudControlLedOn) LED_Toggle(a); else LED_Off(a);}
/*
*********************************************************************************************************
* TEST TABLE
*********************************************************************************************************
*/
static APP_TEST AppTestTbl[] = {
{AppTestTx_Sem1, AppTestRx_Sem1 }, /* 0 */
{AppTestTx_Sem2, AppTestRx_Sem2 }, /* 1 */
{AppTestTx_TaskSem1, AppTestRx_TaskSem1}, /* 2 */
{AppTestTx_TaskSem2, AppTestRx_TaskSem2}, /* 3 */
{AppTestTx_Q1, AppTestRx_Q1 }, /* 4 */
{AppTestTx_Q2, AppTestRx_Q2 }, /* 5 */
{AppTestTx_TaskQ1, AppTestRx_TaskQ1 }, /* 6 */
{AppTestTx_TaskQ2, AppTestRx_TaskQ2 }, /* 7 */
{AppTestTx_Mutex1, AppTestRx_Mutex1 }, /* 8 */
{AppTestTx_Flag1, AppTestRx_Flag1 }, /* 9 */
{AppTestTx_Flag2, AppTestRx_Flag2 }, /* 10 */
{0, 0 }, /* 11, */
{0, 0 }, /* 12, */
{0, 0 }, /* 13, */
{0, 0 }, /* 14, */
{0, 0 }, /* 15, Int Queue Task execution time */
{0, 0 }, /* 16, Stat Task execution time */
{0, 0 }, /* 17, Tick Task execution time */
{0, 0 }, /* 18, Timer Task execution time */
{0, 0 }, /* 19, Maximum interrupt disable time */
{0, 0 }, /* 20, Maximum scheduler lock time */
{0, 0 }
};
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main (void)
{
OS_ERR err;
CPU_IntDis(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
App_OS_SetAllHooks();
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) 0,
(OS_PRIO ) APP_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while (1) {
;
}
return (0);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
NET_ERR net_err;
#endif
(void)&p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */
#if (OS_CFG_STAT_TASK_EN > 0u)
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */
AppObjCreate(); /* Create kernel objects (semaphore, queue, etc.) */
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
AppProbe_Init(); /* Initialize uC/Probe modules */
#endif
BSP_GraphLCD_Init();
AppGraphLCD_Hdr();
AppTaskCreate(); /* Create application tasks */
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */
AppCloud_Init(0);
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
OSTaskDel(&AppTaskStartTCB, /* Delete task because its work is complete */
&err);
while (DEF_ON) {
; /* Should not get here! */
}
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*
* Description: This function creates the application tasks.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
OS_ERR err;
OSTaskCreate((OS_TCB *)&AppTaskRxTCB,
(CPU_CHAR *)"Rx Task",
(OS_TASK_PTR ) AppTaskRx,
(void *) 0,
(OS_PRIO ) APP_TASK_RX_PRIO,
(CPU_STK *)&AppTaskRxStk[0],
(CPU_STK_SIZE) APP_TASK_RX_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_TASK_RX_STK_SIZE,
(OS_MSG_QTY ) 10u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSTaskCreate((OS_TCB *)&AppTaskTxTCB,
(CPU_CHAR *)"Tx Task",
(OS_TASK_PTR ) AppTaskTx,
(void *) 0,
(OS_PRIO ) APP_TASK_TX_PRIO,
(CPU_STK *)&AppTaskTxStk[0],
(CPU_STK_SIZE) APP_TASK_TX_STK_SIZE / 10,
(CPU_STK_SIZE) APP_TASK_TX_STK_SIZE,
(OS_MSG_QTY ) 10u,
(OS_TICK ) 0u,
(void *) 0u,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
}
/*
*********************************************************************************************************
* CREATE APPLICATION KERNEL OBJECTS
*
* Description: This function creates the application kernel objects such as semaphore, queue, etc.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
static void AppObjCreate (void)
{
OS_ERR err;
OSSemCreate ((OS_SEM *)&AppSem,
(CPU_CHAR *)"App Sem",
(OS_SEM_CTR ) 0u,
(OS_ERR *)&err);
OSFlagCreate ((OS_FLAG_GRP *)&AppFlagGrp,
(CPU_CHAR *)"App Flag Group",
(OS_FLAGS ) 0u,
(OS_ERR *)&err);
OSQCreate ((OS_Q *)&AppQ,
(CPU_CHAR *)"App Queue",
(OS_MSG_QTY ) 20u,
(OS_ERR *)&err);
OSMutexCreate((OS_MUTEX *)&AppMutex,
(CPU_CHAR *)"App Mutex",
(OS_ERR *)&err);
}
/*
*********************************************************************************************************
* TX TASK
*
* Description : This task sends signals or messages to the Rx Task
*
* Arguments : p_arg is the argument passed to 'AppTaskTx()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskTx (void *p_arg)
{
OS_ERR err;
OS_MSG_SIZE msg_size;
CPU_TS ts;
APP_TEST *p_test;
(void)p_arg;
while (DEF_ON) { /* Task body, always written as an infinite loop. */
EX_LED_TOGGLE(5);
p_test = (APP_TEST *)OSTaskQPend((OS_TICK )0,
(OS_OPT )OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *)&ts,
(OS_ERR *)&err);
(*p_test->Tx)((CPU_INT08U)msg_size);
}
}
/*
*********************************************************************************************************
* RX TASK
*
* Description : This task receives signals or messages from the Tx Task
*
* Arguments : p_arg is the argument passed to 'AppTaskRx()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskRx (void *p_arg)
{
OS_ERR err;
CPU_ERR cpu_err;
CPU_INT08U i;
APP_TEST *p_test;
(void)&p_arg;
i = 0;
p_test = &AppTestTbl[0];
AppTestSel = 0;
App_TS_to_us = (CPU_FP32)1000000.0f / (CPU_FP32)CPU_TS_TmrFreqGet(&cpu_err);
for (i = 0; i < APP_TEST_MAX; i++) { /* Clear the test data array */
AppTS_Delta[i] = (CPU_TS_TMR)0;
}
while (DEF_ON) { /* Task body, always written as an infinite loop. */
EX_LED_TOGGLE(14);
OSTimeDlyHMSM(0u, 0u, 0u, 50u,
OS_OPT_TIME_HMSM_STRICT,
&err);
if ((void *)p_test->Tx != (void *)0) {
OSTaskQPost((OS_TCB *)&AppTaskTxTCB,
(void *) p_test,
(OS_MSG_SIZE) i,
(OS_OPT ) OS_OPT_POST_FIFO,
(OS_ERR *)&err);
(*(p_test->Rx))(i);
i++;
p_test++;
} else {
i = 0;
p_test = &AppTestTbl[0];
}
/* Copy measured time from other sources */
#if (OS_CFG_ISR_POST_DEFERRED_EN > 0u)
AppTS_Delta[15] = (CPU_TS_TMR)OSIntQTaskTimeMax;
#endif
#if (OS_CFG_STAT_TASK_EN > 0u)
AppTS_Delta[16] = (CPU_TS_TMR)OSStatTaskTimeMax;
#endif
AppTS_Delta[17] = (CPU_TS_TMR)OSTickTaskTimeMax;
#if (OS_CFG_TMR_EN > 0u)
AppTS_Delta[18] = (CPU_TS_TMR)OSTmrTaskTimeMax;
#endif
AppTS_Delta[19] = (CPU_TS_TMR)OSIntDisTimeMax;
AppTS_Delta[20] = (CPU_TS_TMR)OSSchedLockTimeMax;
AppTestTime_us = (CPU_INT16U)((CPU_FP32)AppTS_Delta[AppTestSel] * App_TS_to_us);
}
}
/*
*********************************************************************************************************
* SEMAPHORE TEST(S)
*********************************************************************************************************
*/
void AppTestTx_Sem1 (CPU_INT08U ix)
{
OS_ERR err;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSSemPost((OS_SEM *)&AppSem,
(OS_OPT ) OS_OPT_POST_1,
(OS_ERR *)&err);
}
void AppTestRx_Sem1 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OSSemPend((OS_SEM *)&AppSem,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
void AppTestTx_Sem2 (CPU_INT08U ix)
{
ix = ix;
}
void AppTestRx_Sem2 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSSemPost((OS_SEM *)&AppSem,
(OS_OPT ) OS_OPT_POST_1,
(OS_ERR *)&err);
OSSemPend((OS_SEM *)&AppSem,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
/*
*********************************************************************************************************
* TASK SEMAPHORE TEST(S)
*********************************************************************************************************
*/
void AppTestTx_TaskSem1 (CPU_INT08U ix)
{
OS_ERR err;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSTaskSemPost((OS_TCB *)&AppTaskRxTCB,
(OS_OPT ) OS_OPT_POST_NONE,
(OS_ERR *)&err);
}
void AppTestRx_TaskSem1 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OSTaskSemPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
void AppTestTx_TaskSem2 (CPU_INT08U ix)
{
ix = ix;
}
void AppTestRx_TaskSem2 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSTaskSemPost((OS_TCB *) 0u,
(OS_OPT ) OS_OPT_POST_NONE,
(OS_ERR *)&err);
OSTaskSemPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
/*
*********************************************************************************************************
* MESSAGE QUEUE TEST(S)
*********************************************************************************************************
*/
void AppTestTx_Q1 (CPU_INT08U ix)
{
OS_ERR err;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSQPost((OS_Q *)&AppQ,
(void *) 1,
(OS_MSG_SIZE) 0u,
(OS_OPT ) OS_OPT_POST_FIFO,
(OS_ERR *)&err);
}
void AppTestRx_Q1 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OS_MSG_SIZE msg_size;
(void)OSQPend((OS_Q *)&AppQ,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
void AppTestTx_Q2 (CPU_INT08U ix)
{
ix = ix;
}
void AppTestRx_Q2 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OS_MSG_SIZE msg_size;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSQPost((OS_Q *)&AppQ,
(void *) 1,
(OS_MSG_SIZE) 0u,
(OS_OPT ) OS_OPT_POST_FIFO,
(OS_ERR *)&err);
(void)OSQPend((OS_Q *)&AppQ,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
/*
*********************************************************************************************************
* TASK MESSAGE QUEUE TEST(S)
*********************************************************************************************************
*/
void AppTestTx_TaskQ1 (CPU_INT08U ix)
{
OS_ERR err;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSTaskQPost((OS_TCB *)&AppTaskRxTCB,
(void *) 1,
(OS_MSG_SIZE) 0u,
(OS_OPT ) OS_OPT_POST_FIFO,
(OS_ERR *)&err);
}
void AppTestRx_TaskQ1 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OS_MSG_SIZE msg_size;
(void)OSTaskQPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
void AppTestTx_TaskQ2 (CPU_INT08U ix)
{
ix = ix;
}
void AppTestRx_TaskQ2 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OS_MSG_SIZE msg_size;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSTaskQPost((OS_TCB *) 0,
(void *) 1,
(OS_MSG_SIZE) 0u,
(OS_OPT ) OS_OPT_POST_FIFO,
(OS_ERR *)&err);
(void)OSTaskQPend((OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(OS_MSG_SIZE *)&msg_size,
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
/*
*********************************************************************************************************
* MUTUAL EXCLUSION SEMAPHORE TEST(S)
*********************************************************************************************************
*/
void AppTestTx_Mutex1 (CPU_INT08U ix)
{
ix = ix;
}
void AppTestRx_Mutex1 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSMutexPend((OS_MUTEX *)&AppMutex,
(OS_TICK ) 0u,
(OS_OPT ) OS_OPT_PEND_BLOCKING,
(CPU_TS *)&ts,
(OS_ERR *)&err);
OSMutexPost((OS_MUTEX *)&AppMutex,
(OS_OPT ) OS_OPT_POST_NONE,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
/*
*********************************************************************************************************
* EVENT FLAG TEST(S)
*********************************************************************************************************
*/
void AppTestTx_Flag1 (CPU_INT08U ix)
{
OS_ERR err;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSFlagPost((OS_FLAG_GRP *)&AppFlagGrp,
(OS_FLAGS ) 0xFFu,
(OS_OPT ) OS_OPT_POST_FLAG_SET,
(OS_ERR *)&err);
}
void AppTestRx_Flag1 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
OSFlagPend((OS_FLAG_GRP *)&AppFlagGrp,
(OS_FLAGS ) 0xFFu,
(OS_TICK ) 0u,
(OS_OPT )(OS_OPT_PEND_FLAG_SET_ALL +
OS_OPT_PEND_FLAG_CONSUME +
OS_OPT_PEND_BLOCKING),
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
void AppTestTx_Flag2 (CPU_INT08U ix)
{
ix = ix;
}
void AppTestRx_Flag2 (CPU_INT08U ix)
{
OS_ERR err;
CPU_TS ts;
AppTS_Start[ix] = CPU_TS_TmrRd();
OSFlagPost((OS_FLAG_GRP *)&AppFlagGrp,
(OS_FLAGS ) 0xFFu,
(OS_OPT ) OS_OPT_POST_FLAG_SET,
(OS_ERR *)&err);
OSFlagPend((OS_FLAG_GRP *)&AppFlagGrp,
(OS_FLAGS ) 0xFFu,
(OS_TICK ) 0u,
(OS_OPT )(OS_OPT_PEND_FLAG_SET_ALL +
OS_OPT_PEND_FLAG_CONSUME +
OS_OPT_PEND_BLOCKING),
(CPU_TS *)&ts,
(OS_ERR *)&err);
AppTS_End[ix] = CPU_TS_TmrRd();
AppTS_Delta[ix] = AppTS_End[ix] - AppTS_Start[ix];
}
/*
*********************************************************************************************************
* AppGraphLCD_Hdr()
*********************************************************************************************************
*/
static void AppGraphLCD_Hdr (void)
{
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_LARGE);
BSP_GraphLCD_StringPos(0, 4, "Micrium");
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SMALL);
BSP_GraphLCD_StringPos(1, 5, "uC/OS-III");
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
BSP_GraphLCD_StringPos(2, 5, "uC/TCP-IP");
#endif
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex1/app.c
|
/*
*********************************************************************************************************
* uC/OS-III
* The Real-Time Kernel
*
* (c) Copyright 2010, Micrium, Inc., Weston, FL
* All Rights Reserved
*
*
* File : APP.C
* By : FGK
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_TCB AppTaskStartTCB;
static CPU_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static OS_TCB AppBlinkyTaskTCB;
static CPU_STK AppBlinkyTaskStk[BLINKY_TASK_STK_SIZE];
static CPU_BOOLEAN AppTCPIP_Cfg = DEF_FALSE;
volatile CPU_INT08U AppCloudControlLedOn = 1;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppBlinkyTask (void *p_arg);
static void AppGraphLCD_Hdr(void);
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
void AppTCPIP_Init (NET_ERR *perr);
#endif
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
void AppProbe_Init (void);
#endif
static void LEDDisplaySeq0 (void);
static void LEDDisplaySeq1 (void);
static void LEDDisplaySeq2 (void);
static void LEDDisplaySeq3 (void);
void AppCloud_Init (CPU_BOOLEAN disableStatus);
#define EX_LED_ON(a) {if (AppCloudControlLedOn) LED_On(a); else LED_Off(a);}
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary initialization.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main (void)
{
OS_ERR err;
CPU_IntDis(); /* Disable all interrupts. */
OSInit(&err); /* Init uC/OS-III. */
App_OS_SetAllHooks();
OSTaskCreate((OS_TCB *)&AppTaskStartTCB, /* Create the start task */
(CPU_CHAR *)"App Task Start",
(OS_TASK_PTR ) AppTaskStart,
(void *) 0,
(OS_PRIO ) APP_TASK_START_PRIO,
(CPU_STK *)&AppTaskStartStk[0],
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE / 10u,
(CPU_STK_SIZE) APP_TASK_START_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
OSStart(&err); /* Start multitasking (i.e. give control to uC/OS-III). */
while (1) {
;
}
return (0);
}
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
OS_ERR err;
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
NET_ERR net_err;
#endif
(void)&p_arg;
BSP_Init(); /* Initialize BSP functions */
CPU_Init(); /* Initialize the uC/CPU services */
OS_CPU_TickInit(); /* Init uC/OS periodic time src (SysTick). */
#if (OS_CFG_STAT_TASK_EN > 0u)
OSStatTaskCPUUsageInit(&err); /* Compute CPU capacity with no task running */
#endif
Mem_Init(); /* Initialize mem mgmt module, required for TCP-IP. */
#if (APP_CFG_PROBE_COM_MODULE_EN > 0u)
AppProbe_Init(); /* Initialize uC/Probe modules */
#endif
OSTaskCreate((OS_TCB *)&AppBlinkyTaskTCB, /* Create the start task */
(CPU_CHAR *)"Blinky Task",
(OS_TASK_PTR ) AppBlinkyTask,
(void *) 0,
(OS_PRIO ) BLINKY_TASK_PRIO,
(CPU_STK *)&AppBlinkyTaskStk[0],
(CPU_STK_SIZE) BLINKY_TASK_STK_SIZE / 10u,
(CPU_STK_SIZE) BLINKY_TASK_STK_SIZE,
(OS_MSG_QTY ) 0u,
(OS_TICK ) 0u,
(void *) 0,
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
(OS_ERR *)&err);
BSP_GraphLCD_Init();
AppGraphLCD_Hdr();
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
AppTCPIP_Init(&net_err); /* Initialize uC/TCP-IP & associated applications. */
AppCloud_Init(0);
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
AppTCPIP_Cfg = DEF_TRUE;
OSTaskDel(&AppTaskStartTCB, /* Delete task because its work is complete */
&err);
while (DEF_ON) {
; /* Should not get here! */
}
}
/*
*********************************************************************************************************
* BLINKY TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
*
* Arguments : p_arg is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppBlinkyTask (void *p_arg)
{
OS_ERR err;
static CPU_INT08U seq = 0;
(void)&p_arg;
LED_Off(0); /* turn all LEDs off */
while (DEF_ON) { /* Task body, always written as an infinite loop. */
if(AppTCPIP_Cfg == DEF_FALSE){
LED_Toggle(14); /* simple LED flash */
LED_Toggle( 5);
LED_Toggle( 8);
LED_Toggle(11);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
} else {
switch (seq){
case 0:
LEDDisplaySeq0();
seq++;
break;
case 1:
LEDDisplaySeq1();
seq++;
break;
case 2:
LEDDisplaySeq2();
seq++;
break;
case 3:
LEDDisplaySeq3();
seq = 0;
break;
default:
seq = 0;
break;
}
}
}
}
static void LEDDisplaySeq0 (void)
{
CPU_INT08U i;
CPU_INT08U j;
OS_ERR err;
LED_Off(0);
for (i = 14; i > 4; i--) {
EX_LED_ON(i);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
LED_Off(i);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
for (i = 4; i <= 15; i++) {
EX_LED_ON(i);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
LED_Off(i);
OSTimeDlyHMSM(0u, 0u, 0u, 100u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
static void LEDDisplaySeq1 (void)
{
CPU_INT08U i;
CPU_INT08U j;
OS_ERR err;
LED_Off(0);
for (i = 4; i <= 15; i++) {
EX_LED_ON(i);
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
for (i = 15; i > 4; i--) {
LED_Off(i);
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
static void LEDDisplaySeq2 (void)
{
CPU_INT08U i;
CPU_INT08U j;
OS_ERR err;
LED_Off(0);
j = 15;
for (i = 4; i <= 9; i++) {
EX_LED_ON(i);
EX_LED_ON(j);
j--;
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
j = 15;
for (i = 4; i <= 8; i++) {
LED_Off(i);
LED_Off(j);
j--;
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
j = 11;
for (i = 8; i >= 4; i--) {
EX_LED_ON(i);
EX_LED_ON(j);
j++;
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
j = 10;
for (i=9; i >= 4; i--) {
LED_Off(i);
LED_Off(j);
j++;
OSTimeDlyHMSM(0u, 0u, 0u, 200u,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
static void LEDDisplaySeq3 (void)
{
CPU_INT08U i;
CPU_INT08U j;
CPU_INT08U delay;
OS_ERR err;
LED_Off(0);
for (delay = 100; delay > 20; delay -= 5) {
for (i = 4; i < 7; i++) {
EX_LED_ON(i);
EX_LED_ON(i + 3);
EX_LED_ON(i + 6);
EX_LED_ON(i + 9);
OSTimeDlyHMSM(0u, 0u, 0u, delay,
OS_OPT_TIME_HMSM_STRICT,
&err);
LED_Off(i);
LED_Off(i + 3);
LED_Off(i + 6);
LED_Off(i + 9);
OSTimeDlyHMSM(0u, 0u, 0u, delay,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
for (delay = 25; delay <= 100; delay += 5) {
for (i = 4; i < 7; i++) {
EX_LED_ON(i);
EX_LED_ON(i + 3);
EX_LED_ON(i + 6);
EX_LED_ON(i + 9);
OSTimeDlyHMSM(0u, 0u, 0u, delay,
OS_OPT_TIME_HMSM_STRICT,
&err);
LED_Off(i);
LED_Off(i + 3);
LED_Off(i + 6);
LED_Off(i + 9);
OSTimeDlyHMSM(0u, 0u, 0u, delay,
OS_OPT_TIME_HMSM_STRICT,
&err);
}
}
}
/*
*********************************************************************************************************
* AppGraphLCD_Hdr()
*********************************************************************************************************
*/
static void AppGraphLCD_Hdr (void)
{
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_LARGE);
BSP_GraphLCD_StringPos(0, 4, "Micrium");
BSP_GraphLCD_SetFont(BSP_GLCD_FONT_SMALL);
BSP_GraphLCD_StringPos(1, 5, "uC/OS-III");
#if (APP_CFG_TCPIP_MODULE_EN > 0u)
BSP_GraphLCD_StringPos(2, 5, "uC/TCP-IP");
#endif
}
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/Init/inthandler.c
|
/***********************************************************************/
/* */
/* FILE :inthandler.c */
/* DATE :Mon, Jun 28, 2010 */
/* DESCRIPTION :Interrupt Handler */
/* CPU TYPE :Other */
/* */
/* This file is generated by KPIT GNU Project Generator. */
/* */
/***********************************************************************/
#include "inthandler.h"
// Exception(Supervisor Instruction)
void INT_Excep_SuperVisorInst(void){/* brk(); */}
// Exception(Undefined Instruction)
void INT_Excep_UndefinedInst(void){/* brk(); */}
// Exception(Floating Point)
void INT_Excep_FloatingPoint(void){/* brk(); */}
// NMI
void INT_NonMaskableInterrupt(void){/* brk(); */}
// Dummy
void Dummy(void){/* brk(); */}
// BRK
void INT_Excep_BRK(void){ /*wait(); */}
// BUSERR
void INT_Excep_BUSERR(void){ }
// FCU_FCUERR
void INT_Excep_FCU_FCUERR(void){ }
// FCU_FRDYI
void INT_Excep_FCU_FRDYI(void){ }
// ICU_SWINT
void INT_Excep_ICU_SWINT(void){ }
// CMTU0_CMT0
void INT_Excep_CMTU0_CMT0(void){ }
// CMTU0_CMT1
void INT_Excep_CMTU0_CMT1(void){ }
// CMTU1_CMT2
void INT_Excep_CMTU1_CMT2(void){ }
// CMTU1_CMT3
void INT_Excep_CMTU1_CMT3(void){ }
// Ether_EINT
void INT_Excep_Ether_EINT(void){ }
// USB0_D0FIFO0
void INT_Excep_USB0_D0FIFO0(void){ }
// USB0_D1FIFO0
void INT_Excep_USB0_D1FIFO0(void){ }
// USB0_USBI0
void INT_Excep_USB0_USBI0(void){ }
// USB1_D0FIFO1
void INT_Excep_USB1_D0FIFO1(void){ }
// USB1_D1FIFO1
void INT_Excep_USB1_D1FIFO1(void){ }
// USB1_USBI1
void INT_Excep_USB1_USBI1(void){ }
// RSPI0_SPEI0
void INT_Excep_RSPI0_SPEI0(void){ }
// RSPI0_SPRI0
void INT_Excep_RSPI0_SPRI0(void){ }
// RSPI0_SPTI0
void INT_Excep_RSPI0_SPTI0(void){ }
// RSPI0_SPII0
void INT_Excep_RSPI0_SPII0(void){ }
// RSPI1_SPEI1
void INT_Excep_RSPI1_SPEI1(void){ }
// RSPI1_SPRI1
void INT_Excep_RSPI1_SPRI1(void){ }
// RSPI1_SPTI1
void INT_Excep_RSPI1_SPTI1(void){ }
// RSPI1_SPII1
void INT_Excep_RSPI1_SPII1(void){ }
// CAN0_ERS0
void INT_Excep_CAN0_ERS0(void){ }
// CAN0_RXF0
void INT_Excep_CAN0_RXF0(void){ }
// CAN0_TXF0
void INT_Excep_CAN0_TXF0(void){ }
// CAN0_RXM0
void INT_Excep_CAN0_RXM0(void){ }
// CAN0_TXM0
void INT_Excep_CAN0_TXM0(void){ }
// RTC_PRD
void INT_Excep_RTC_PRD(void){ }
// RTC_CUP
void INT_Excep_RTC_CUP(void){ }
// IRQ0
void INT_Excep_IRQ0(void){ }
// IRQ1
void INT_Excep_IRQ1(void){ }
// IRQ2
void INT_Excep_IRQ2(void){ }
// IRQ3
void INT_Excep_IRQ3(void){ }
// IRQ4
void INT_Excep_IRQ4(void){ }
// IRQ5
void INT_Excep_IRQ5(void){ }
// IRQ6
void INT_Excep_IRQ6(void){ }
// IRQ7
void INT_Excep_IRQ7(void){ }
// IRQ8
void INT_Excep_IRQ8(void){ }
// IRQ9
void INT_Excep_IRQ9(void){ }
// IRQ10
void INT_Excep_IRQ10(void){ }
// IRQ11
void INT_Excep_IRQ11(void){ }
// IRQ12
void INT_Excep_IRQ12(void){ }
// IRQ13
void INT_Excep_IRQ13(void){ }
// IRQ14
void INT_Excep_IRQ14(void){ }
// IRQ15
void INT_Excep_IRQ15(void){ }
// USB_resume_USBR0
void INT_Excep_USB_resume_USBR0(void){ }
// USB_resume_USBR1
void INT_Excep_USB_resume_USBR1(void){ }
// RTC_ALM
void INT_Excep_RTC_ALM(void){ }
// WDT_WOVI
void INT_Excep_WDT_WOVI(void){ }
// AD0_ADI0
void INT_Excep_AD0_ADI0(void){ }
// AD1_ADI1
void INT_Excep_AD1_ADI1(void){ }
// S12AD_ADI12_0
void INT_Excep_S12AD_ADI12_0(void){ }
// MTU0_TGIA0
void INT_Excep_MTU0_TGIA0(void){ }
// MTU0_TGIB0
void INT_Excep_MTU0_TGIB0(void){ }
// MTU0_TGIC0
void INT_Excep_MTU0_TGIC0(void){ }
// MTU0_TGID0
void INT_Excep_MTU0_TGID0(void){ }
// MTU0_TGIV0
void INT_Excep_MTU0_TGIV0(void){ }
// MTU0_TGIE0
void INT_Excep_MTU0_TGIE0(void){ }
// MTU0_TGIF0
void INT_Excep_MTU0_TGIF0(void){ }
// MTU1_TGIA1
void INT_Excep_MTU1_TGIA1(void){ }
// MTU1_TGIB1
void INT_Excep_MTU1_TGIB1(void){ }
// MTU1_TGIV1
void INT_Excep_MTU1_TGIV1(void){ }
// MTU1_TGIU1
void INT_Excep_MTU1_TGIU1(void){ }
// MTU2_TGIA2
void INT_Excep_MTU2_TGIA2(void){ }
// MTU2_TGIB2
void INT_Excep_MTU2_TGIB2(void){ }
// MTU2_TGIV2
void INT_Excep_MTU2_TGIV2(void){ }
// MTU2_TGIU2
void INT_Excep_MTU2_TGIU2(void){ }
// MTU3_TGIA3
void INT_Excep_MTU3_TGIA3(void){ }
// MTU3_TGIB3
void INT_Excep_MTU3_TGIB3(void){ }
// MTU3_TGIC3
void INT_Excep_MTU3_TGIC3(void){ }
// MTU3_TGID3
void INT_Excep_MTU3_TGID3(void){ }
// MTU3_TGIV3
void INT_Excep_MTU3_TGIV3(void){ }
// MTU4_TGIA4
void INT_Excep_MTU4_TGIA4(void){ }
// MTU4_TGIB4
void INT_Excep_MTU4_TGIB4(void){ }
// MTU4_TGIC4
void INT_Excep_MTU4_TGIC4(void){ }
// MTU4_TGID4
void INT_Excep_MTU4_TGID4(void){ }
// MTU4_TGIV4
void INT_Excep_MTU4_TGIV4(void){ }
// MTU5_TGIU5
void INT_Excep_MTU5_TGIU5(void){ }
// MTU5_TGIV5
void INT_Excep_MTU5_TGIV5(void){ }
// MTU5_TGIW5
void INT_Excep_MTU5_TGIW5(void){ }
// MTU6_TGIA6
void INT_Excep_MTU6_TGIA6(void){ }
// MTU6_TGIB6
void INT_Excep_MTU6_TGIB6(void){ }
// MTU6_TGIC6
void INT_Excep_MTU6_TGIC6(void){ }
// MTU6_TGID6
void INT_Excep_MTU6_TGID6(void){ }
// MTU6_TGIV6
void INT_Excep_MTU6_TGIV6(void){ }
// MTU6_TGIE6
void INT_Excep_MTU6_TGIE6(void){ }
// MTU6_TGIF6
void INT_Excep_MTU6_TGIF6(void){ }
// MTU7_TGIA7
void INT_Excep_MTU7_TGIA7(void){ }
// MTU7_TGIB7
void INT_Excep_MTU7_TGIB7(void){ }
// MTU7_TGIV7
void INT_Excep_MTU7_TGIV7(void){ }
// MTU7_TGIU7
void INT_Excep_MTU7_TGIU7(void){ }
// MTU8_TGIA8
void INT_Excep_MTU8_TGIA8(void){ }
// MTU8_TGIB8
void INT_Excep_MTU8_TGIB8(void){ }
// MTU8_TGIV8
void INT_Excep_MTU8_TGIV8(void){ }
// MTU8_TGIU8
void INT_Excep_MTU8_TGIU8(void){ }
// MTU9_TGIA9
void INT_Excep_MTU9_TGIA9(void){ }
// MTU9_TGIB9
void INT_Excep_MTU9_TGIB9(void){ }
// MTU9_TGIC9
void INT_Excep_MTU9_TGIC9(void){ }
// MTU9_TGID9
void INT_Excep_MTU9_TGID9(void){ }
// MTU9_TGIV9
void INT_Excep_MTU9_TGIV9(void){ }
// MTU10_TGIA10
void INT_Excep_MTU10_TGIA10(void){ }
// MTU10_TGIB10
void INT_Excep_MTU10_TGIB10(void){ }
// MTU10_TGIC10
void INT_Excep_MTU10_TGIC10(void){ }
// MTU10_TGID10
void INT_Excep_MTU10_TGID10(void){ }
// MTU10_TGIV10
void INT_Excep_MTU10_TGIV10(void){ }
// MTU11_TGIU11
void INT_Excep_MTU11_TGIU11(void){ }
// MTU11_TGIV11
void INT_Excep_MTU11_TGIV11(void){ }
// MTU11_TGIW11
void INT_Excep_MTU11_TGIW11(void){ }
// POE_OEI1
void INT_Excep_POE_OEI1(void){ }
// POE_OEI2
void INT_Excep_POE_OEI2(void){ }
// POE_OEI3
void INT_Excep_POE_OEI3(void){ }
// POE_OEI4
void INT_Excep_POE_OEI4(void){ }
// TMR0_CMI0A
void INT_Excep_TMR0_CMI0A(void){ }
// TMR0_CMI0B
void INT_Excep_TMR0_CMI0B(void){ }
// TMR0_OV0I
void INT_Excep_TMR0_OV0I(void){ }
// TMR1_CMI1A
void INT_Excep_TMR1_CMI1A(void){ }
// TMR1_CMI1B
void INT_Excep_TMR1_CMI1B(void){ }
// TMR1_OV1I
void INT_Excep_TMR1_OV1I(void){ }
// TMR2_CMI2A
void INT_Excep_TMR2_CMI2A(void){ }
// TMR2_CMI2B
void INT_Excep_TMR2_CMI2B(void){ }
// TMR2_OV2I
void INT_Excep_TMR2_OV2I(void){ }
// TMR3_CMI3A
void INT_Excep_TMR3_CMI3A(void){ }
// TMR3_CMI3B
void INT_Excep_TMR3_CMI3B(void){ }
// TMR3_OV3I
void INT_Excep_TMR3_OV3I(void){ }
// DMACA_DMAC0I
void INT_Excep_DMACA_DMAC0I(void){ }
// DMACA_DMAC1I
void INT_Excep_DMACA_DMAC1I(void){ }
// DMACA_DMAC2I
void INT_Excep_DMACA_DMAC2I(void){ }
// DMACA_DMAC3I
void INT_Excep_DMACA_DMAC3I(void){ }
// EXDMAC_EXDMAC0I
void INT_Excep_EXDMAC_EXDMAC0I(void){ }
// EXDMAC_EXDMAC1I
void INT_Excep_EXDMAC_EXDMAC1I(void){ }
// SCI0_ERI0
void INT_Excep_SCI0_ERI0(void){ }
// SCI0_RXI0
void INT_Excep_SCI0_RXI0(void){ }
// SCI0_TXI0
void INT_Excep_SCI0_TXI0(void){ }
// SCI0_TEI0
void INT_Excep_SCI0_TEI0(void){ }
// SCI1_ERI1
void INT_Excep_SCI1_ERI1(void){ }
// SCI1_RXI1
void INT_Excep_SCI1_RXI1(void){ }
// SCI1_TXI1
void INT_Excep_SCI1_TXI1(void){ }
// SCI1_TEI1
void INT_Excep_SCI1_TEI1(void){ }
// SCI2_ERI2
void INT_Excep_SCI2_ERI2(void){ }
// SCI2_RXI2
void INT_Excep_SCI2_RXI2(void){ }
// SCI2_TXI2
void INT_Excep_SCI2_TXI2(void){ }
// SCI2_TEI2
void INT_Excep_SCI2_TEI2(void){ }
// SCI3_ERI3
void INT_Excep_SCI3_ERI3(void){ }
// SCI3_RXI3
void INT_Excep_SCI3_RXI3(void){ }
// SCI3_TXI3
void INT_Excep_SCI3_TXI3(void){ }
// SCI3_TEI3
void INT_Excep_SCI3_TEI3(void){ }
// SCI5_ERI5
void INT_Excep_SCI5_ERI5(void){ }
// SCI5_RXI5
void INT_Excep_SCI5_RXI5(void){ }
// SCI5_TXI5
void INT_Excep_SCI5_TXI5(void){ }
// SCI5_TEI5
void INT_Excep_SCI5_TEI5(void){ }
// SCI6_ERI6
void INT_Excep_SCI6_ERI6(void){ }
// SCI6_RXI6
void INT_Excep_SCI6_RXI6(void){ }
// SCI6_TXI6
void INT_Excep_SCI6_TXI6(void){ }
// SCI6_TEI6
void INT_Excep_SCI6_TEI6(void){ }
// RIIC0_ICEEI0
void INT_Excep_RIIC0_ICEEI0(void){ }
// RIIC0_ICRXI0
void INT_Excep_RIIC0_ICRXI0(void){ }
// RIIC0_ICTXI0
void INT_Excep_RIIC0_ICTXI0(void){ }
// RIIC0_ICTEI0
void INT_Excep_RIIC0_ICTEI0(void){ }
// RIIC1_EEI1
void INT_Excep_RIIC1_ICEEI1(void){ }
// RIIC1_RXI1
void INT_Excep_RIIC1_ICRXI1(void){ }
// RIIC1_TXI1
void INT_Excep_RIIC1_ICTXI1(void){ }
// RIIC1_TEI1
void INT_Excep_RIIC1_ICTEI1(void){ }
|
nbarjolin/micrium_gnurx_cloud
|
uCOS-III-Ex6/fs_app.c
|
/*
*********************************************************************************************************
* uC/FS V4
* The Embedded File System
*
* (c) Copyright 2008-2011; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/FS is provided in source form to registered licensees ONLY. It is
* illegal to distribute this source code to any third party unless you receive
* written permission by an authorized Micrium representative. Knowledge of
* the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*
* You can contact us at www.micrium.com.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* FILE SYSTEM APPLICATION INITIALIZATION
*
* TEMPLATE
*
* Filename : fs_app.c
* Version : V4.04
* Programmer(s) : BAN
* AHFAI
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <fs_app.h>
/*
*********************************************************************************************************
* ENABLE
*********************************************************************************************************
*/
#if (APP_CFG_FS_EN == DEF_ENABLED)
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
#if (APP_CFG_FS_RAM_EN == DEF_ENABLED)
static CPU_INT32U App_FS_RAM_Disk[APP_CFG_FS_RAM_SEC_SIZE * APP_CFG_FS_RAM_NBR_SECS / 4];
#endif
static const FS_CFG App_FS_Cfg = {
APP_CFG_FS_DEV_CNT, /* DevCnt */
APP_CFG_FS_VOL_CNT, /* VolCnt */
APP_CFG_FS_FILE_CNT, /* FileCnt */
APP_CFG_FS_DIR_CNT, /* DirCnt */
APP_CFG_FS_BUF_CNT, /* BufCnt */
APP_CFG_FS_DEV_DRV_CNT, /* DevDrvCnt */
APP_CFG_FS_MAX_SEC_SIZE /* MaxSecSize */
};
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
#if (APP_CFG_FS_MSC_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddMSC (void);
#endif
#if (APP_CFG_FS_IDE_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddIDE (void);
#endif
#if (APP_CFG_FS_NAND_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddNAND (void);
#endif
#if (APP_CFG_FS_NOR_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddNOR (void);
#endif
#if (APP_CFG_FS_RAM_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddRAM (void);
#endif
#if (APP_CFG_FS_SD_CARD_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddSD_Card(void);
#endif
#if (APP_CFG_FS_SD_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddSD_SPI (void);
#endif
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* App_FS_Init()
*
* Description : Initialize uC/FS.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if file system suite was initialized.
* DEF_FAIL, otherwise.
*
* Caller(s) : Application.
*
* Note(s) : (1) MSC device/volumes will be opened/closed dynamically by the USB Host MSC notification
* callback.
*********************************************************************************************************
*/
CPU_BOOLEAN App_FS_Init (void)
{
FS_ERR err;
CPU_BOOLEAN ok;
/* ---------------------- INIT FS --------------------- */
APP_TRACE_DBG(("\r\n"));
APP_TRACE_DBG(("===================================================================\r\n"));
APP_TRACE_DBG(("= FS INITIALIZATION =\r\n"));
APP_TRACE_DBG(("===================================================================\r\n"));
APP_TRACE_DBG(("Initializing FS...\r\n"));
err = FS_Init((FS_CFG *)&App_FS_Cfg);
if (err != FS_ERR_NONE) {
APP_TRACE_DBG(("...init failed w/err = %d\r\n\r\n", err));
return (DEF_FAIL);
}
#if (APP_CFG_FS_MSC_EN == DEF_ENABLED) /* ------------------ ADD MSC DRIVER ------------------ */
ok = App_FS_AddMSC();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
#if (APP_CFG_FS_IDE_EN == DEF_ENABLED) /* ---------------- ADD/OPEN IDE VOLUME --------------- */
ok = App_FS_AddIDE();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
#if (APP_CFG_FS_NAND_EN == DEF_ENABLED) /* ---------------- ADD/OPEN NAND VOLUME -------------- */
ok = App_FS_AddNAND();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
#if (APP_CFG_FS_NOR_EN == DEF_ENABLED) /* ---------------- ADD/OPEN NOR VOLUME --------------- */
ok = App_FS_AddNOR();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
#if (APP_CFG_FS_RAM_EN == DEF_ENABLED) /* ------------- ADD/OPEN RAM DISK VOLUME ------------- */
ok = App_FS_AddRAM();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
#if (APP_CFG_FS_SD_CARD_EN == DEF_ENABLED) /* --------- ADD/OPEN SD/MMC (CARDMODE) VOLUME -------- */
ok = App_FS_AddSD_Card();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
#if (APP_CFG_FS_SD_EN == DEF_ENABLED) /* ----------- ADD/OPEN SD/MMC (SPI) VOLUME ----------- */
ok = App_FS_AddSD_SPI();
if (ok != DEF_OK) {
return (DEF_FAIL);
}
#endif
APP_TRACE_DBG(("...init succeeded.\r\n"));
APP_TRACE_DBG(("===================================================================\r\n"));
APP_TRACE_DBG(("===================================================================\r\n"));
APP_TRACE_DBG(("\r\n"));
return (DEF_OK);
}
/*
*********************************************************************************************************
* App_FS_AddMSC()
*
* Description : Add MSC driver.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
*********************************************************************************************************
*/
#if (APP_CFG_FS_MSC_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddMSC (void)
{
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding MSC device driver ...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_MSC, /* Add MSC device driver (see Note #1). */
(FS_ERR *)&err);
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ... could not add MSC driver w/err = %d\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* App_FS_AddIDE()
*
* Description : Add IDE/CF volume.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
* Note(s) : (1) A device error will be returned from FSDev_Open() & FSVol_Open() if the card is not
* present or malfunctions. The device or volume, respectively, is still open, though
* the device & volume information will need to be refreshed before the medium is
* accessible.
*
* (2) A volume error will be returned from FSVol_Open() if no valid file system is found
* on the card. It may need to be formatted.
*********************************************************************************************************
*/
#if (APP_CFG_FS_IDE_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddIDE (void)
{
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding/opening IDE volume \"ide:0:\"...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_IDE, /* Add IDE/CF device driver. */
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) &&
(err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
APP_TRACE_DBG((" ...could not add driver w/err = %d\r\n\r\n", &err));
return (DEF_FAIL);
}
/* --------------------- OPEN DEV --------------------- */
FSDev_Open("ide:0:", (void *)0, &err); /* Open device "ide:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened device.\r\n"));
break;
case FS_ERR_DEV: /* Device error (see Note #1). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
APP_TRACE_DBG((" ...opened device (not present).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening device failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
/* --------------------- OPEN VOL --------------------- */
FSVol_Open("ide:0:", "ide:0:", 0, &err); /* Open volume "ide:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_DEV: /* Device error (see Note #1). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error (see Note #2). */
APP_TRACE_DBG((" ...opened volume (unmounted).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* App_FS_AddNAND()
*
* Description : Add NAND volume.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
* Note(s) : (1) (a) A device error will be returned from FSDev_Open(), FSVol_Open(), FSDev_NOR_LowFmt()
* or FSVol_Fmt() if the device malfunctions. The device may still be open;
* however, since NOR flash are fixed devices assumed to be always-functioning, an
* application change will be necessary to fully address the problem.
*
* (b) A low-level format invalid error will be returned from FSDev_Open() if the device
* is not low-level formatted.
*
* (2) A partition-not-found error will be returned from FSVol_Open() if the device is not
* formatted (this will always be the situation immediately after FSDev_NAND_LowFmt()).
*********************************************************************************************************
*/
#if (APP_CFG_FS_NAND_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddNAND (void)
{
FS_DEV_NAND_CFG nand_cfg;
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding/opening NAND volume \"nand:0:\"...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_NAND, /* Add NAND device driver. */
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) &&
(err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
APP_TRACE_DBG((" ...could not add driver w/err = %d\r\n\r\n", &err));
return (DEF_FAIL);
}
/* --------------------- OPEN DEV --------------------- */
nand_cfg.BlkNbrFirst = APP_CFG_FS_NAND_BLK_NBR_FIRST;
nand_cfg.BlkCnt = APP_CFG_FS_NAND_BLK_CNT;
nand_cfg.SecSize = APP_CFG_FS_NAND_SEC_SIZE;
nand_cfg.RBCnt = APP_CFG_FS_NAND_RB_CNT;
nand_cfg.PhyPtr = (FS_DEV_NAND_PHY_API *)APP_CFG_FS_NAND_PHY_PTR;
nand_cfg.BusWidth = APP_CFG_FS_NAND_BUS_WIDTH;
nand_cfg.MaxClkFreq = APP_CFG_FS_NAND_MAX_CLK_FREQ;
FSDev_Open("nand:0:", (void *)&nand_cfg, &err); /* Open device "nand:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened device.\r\n"));
break;
case FS_ERR_DEV_INVALID_LOW_FMT: /* Low fmt invalid (see Note #1b). */
APP_TRACE_DBG((" ...opened device (not low-level formatted).\r\n"));
#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)
FSDev_NAND_LowFmt("nand:0:", &err);
#endif
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...low-level format failed.\r\n"));
return (DEF_FAIL);
}
break;
case FS_ERR_DEV: /* Device error (see Note #1a). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
default:
APP_TRACE_DBG((" ...opening device failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
/* --------------------- OPEN VOL --------------------- */
FSVol_Open("nand:0:", "nand:0:", 0, &err); /* Open volume "nand:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error (see Note #2). */
APP_TRACE_DBG((" ...opened device (not formatted).\r\n"));
#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)
FSVol_Fmt("nand:0:", (void *)0, &err);
#endif
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...format failed.\r\n"));
return (DEF_FAIL);
}
break;
case FS_ERR_DEV: /* Device error (see Note #1a). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
APP_TRACE_DBG((" ...opened volume (unmounted).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* App_FS_AddNOR()
*
* Description : Add NOR volume.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
* Note(s) : (1) (a) A device error will be returned from FSDev_Open(), FSVol_Open(), FSDev_NOR_LowFmt()
* or FSVol_Fmt() if the device malfunctions. The device may still be open;
* however, since NOR flash are fixed devices assumed to be always-functioning, an
* application change will be necessary to fully address the problem.
*
* (b) A low-level format invalid error will be returned from FSDev_Open() if the device
* is not low-level formatted.
*
* (2) A partition-not-found error will be returned from FSVol_Open() if the device is not
* formatted (this will always be the situation immediately after FSDev_NOR_LowFmt()).
*********************************************************************************************************
*/
#if (APP_CFG_FS_NOR_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddNOR (void)
{
FS_DEV_NOR_CFG nor_cfg;
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding/opening NOR volume \"nor:0:\"...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_NOR, /* Add NOR device driver. */
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) &&
(err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
APP_TRACE_DBG((" ...could not add driver w/err = %d\r\n\r\n", &err));
return (DEF_FAIL);
}
/* --------------------- OPEN DEV --------------------- */
nor_cfg.AddrBase = APP_CFG_FS_NOR_ADDR_BASE;
nor_cfg.RegionNbr = APP_CFG_FS_NOR_REGION_NBR;
nor_cfg.AddrStart = APP_CFG_FS_NOR_ADDR_START;
nor_cfg.DevSize = APP_CFG_FS_NOR_DEV_SIZE;
nor_cfg.SecSize = APP_CFG_FS_NOR_SEC_SIZE;
nor_cfg.PctRsvd = APP_CFG_FS_NOR_PCT_RSVD;
nor_cfg.EraseCntDiffTh = APP_CFG_FS_NOR_ERASE_CNT_DIFF_TH;
nor_cfg.PhyPtr = (FS_DEV_NOR_PHY_API *)APP_CFG_FS_NOR_PHY_PTR;
nor_cfg.BusWidth = APP_CFG_FS_NOR_BUS_WIDTH;
nor_cfg.BusWidthMax = APP_CFG_FS_NOR_BUS_WIDTH_MAX;
nor_cfg.PhyDevCnt = APP_CFG_FS_NOR_PHY_DEV_CNT;
nor_cfg.MaxClkFreq = APP_CFG_FS_NOR_MAX_CLK_FREQ;
FSDev_Open("nor:0:", (void *)&nor_cfg, &err); /* Open device "nor:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened device.\r\n"));
break;
case FS_ERR_DEV_INVALID_LOW_FMT: /* Low fmt invalid (see Note #1b). */
APP_TRACE_DBG((" ...opened device (not low-level formatted).\r\n"));
#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)
FSDev_NOR_LowFmt("nor:0:", &err);
#endif
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...low-level format failed.\r\n"));
return (DEF_FAIL);
}
break;
case FS_ERR_DEV: /* Device error (see Note #1a). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
default:
APP_TRACE_DBG((" ...opening device failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
/* --------------------- OPEN VOL --------------------- */
FSVol_Open("nor:0:", "nor:0:", 0, &err); /* Open volume "nor:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error (see Note #2). */
APP_TRACE_DBG((" ...opened device (not formatted).\r\n"));
#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)
FSVol_Fmt("nor:0:", (void *)0, &err);
#endif
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...format failed.\r\n"));
return (DEF_FAIL);
}
break;
case FS_ERR_DEV: /* Device error (see Note #1a). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
APP_TRACE_DBG((" ...opened volume (unmounted).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* App_FS_AddRAM()
*
* Description : Add RAM disk volume.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
* Note(s) : (1) A partition-not-found error will be returned from FSVol_Open() if the device is not
* formatted (for a RAM disk, this will typically be the situation immediately after
* FSDev_Open()).
*********************************************************************************************************
*/
#if (APP_CFG_FS_RAM_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddRAM (void)
{
FS_DEV_RAM_CFG ram_cfg;
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding/opening RAM disk volume \"ram:0:\"...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_RAM, /* Add RAM disk driver. */
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) &&
(err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
APP_TRACE_DBG((" ...could not add driver w/err = %d\r\n\r\n", &err));
return (DEF_FAIL);
}
/* --------------------- OPEN DEV --------------------- */
/* Assign RAM disk configuration ... */
ram_cfg.SecSize = APP_CFG_FS_RAM_SEC_SIZE; /* ... (a) sector size ... */
ram_cfg.Size = APP_CFG_FS_RAM_NBR_SECS; /* ... (b) disk size (in sectors)... */
ram_cfg.DiskPtr = (void *)&App_FS_RAM_Disk[0]; /* ... (c) pointer to disk RAM. */
FSDev_Open("ram:0:", (void *)&ram_cfg, &err); /* Open device "ram:0:". */
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...opening device failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
APP_TRACE_DBG((" ...opened device.\r\n"));
/* --------------------- OPEN VOL --------------------- */
FSVol_Open("ram:0:", "ram:0:", 0, &err); /* Open volume "ram:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error (see Note #1). */
APP_TRACE_DBG((" ...opened device (not formatted).\r\n"));
#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)
FSVol_Fmt("ram:0:", (void *)0, &err);
#endif
if (err != FS_ERR_NONE) {
APP_TRACE_DBG((" ...format failed.\r\n"));
return (DEF_FAIL);
}
break;
case FS_ERR_DEV:
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
default:
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* App_FS_AddSD_Card()
*
* Description : Add SD/MMC (CardMode) volume.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
* Note(s) : (1) A device error will be returned from FSDev_Open() & FSVol_Open() if the card is not
* present or malfunctions. The device or volume, respectively, is still open, though
* the device & volume information will need to be refreshed before the medium is
* accessible.
*
* (2) A volume error will be returned from FSVol_Open() if no valid file system is found
* on the card. It may need to be formatted.
*********************************************************************************************************
*/
#if (APP_CFG_FS_SD_CARD_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddSD_Card (void)
{
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding/opening SD/MMC (CardMode) volume \"sdcard:0:\"...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_SD_Card, /* Add SD/MMC (CardMode) device driver. */
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) &&
(err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
APP_TRACE_DBG((" ...could not add driver w/err = %d\r\n\r\n", &err));
return (DEF_FAIL);
}
/* --------------------- OPEN DEV --------------------- */
FSDev_Open("sdcard:0:", (void *)0, &err); /* Open device "sdcard:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened device.\r\n"));
break;
case FS_ERR_DEV: /* Device error (see Note #1). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
APP_TRACE_DBG((" ...opened device (not present).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening device failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
/* --------------------- OPEN VOL --------------------- */
FSVol_Open("sdcard:0:", "sdcard:0:", 0, &err); /* Open volume "sdcard:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_DEV: /* Device error (see Note #1). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error (see Note #2). */
APP_TRACE_DBG((" ...opened volume (unmounted).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* App_FS_AddSD_SPI()
*
* Description : Add SD/MMC (SPI) volume.
*
* Argument(s) : none.
*
* Return(s) : DEF_OK, if volume opened.
* DEF_FAIL, otherwise.
*
* Caller(s) : App_FS_Init().
*
* Note(s) : (1) A device error will be returned from FSDev_Open() & FSVol_Open() if the card is not
* present or malfunctions. The device or volume, respectively, is still open, though
* the device & volume information will need to be refreshed before the medium is
* accessible.
*
* (2) A volume error will be returned from FSVol_Open() if no valid file system is found
* on the card. It is then formatted.
*********************************************************************************************************
*/
#if (APP_CFG_FS_SD_EN == DEF_ENABLED)
static CPU_BOOLEAN App_FS_AddSD_SPI (void)
{
FS_ERR err;
APP_TRACE_DBG((" =========================================================== \r\n"));
APP_TRACE_DBG((" Adding/opening SD/MMC (SPI) volume \"sd:0:\"...\r\n"));
FS_DevDrvAdd((FS_DEV_API *)&FSDev_SD_SPI, /* Add SD/MMC (SPI) device driver. */
(FS_ERR *)&err);
if ((err != FS_ERR_NONE) &&
(err != FS_ERR_DEV_DRV_ALREADY_ADDED)) {
APP_TRACE_DBG((" ...could not add driver w/err = %d\r\n\r\n", &err));
return (DEF_FAIL);
}
/* --------------------- OPEN DEV --------------------- */
FSDev_Open("sd:0:", (void *)0, &err); /* Open device "sd:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened device.\r\n"));
break;
case FS_ERR_DEV: /* Device error (see Note #1). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
APP_TRACE_DBG((" ...opened device (not present).\r\n"));
return (DEF_FAIL);
default:
APP_TRACE_DBG((" ...opening device failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
/* --------------------- OPEN VOL --------------------- */
FSVol_Open("sd:0:", "sd:0:", 0u, &err); /* Open volume "sd:0:". */
switch (err) {
case FS_ERR_NONE:
APP_TRACE_DBG((" ...opened volume (mounted).\r\n"));
break;
case FS_ERR_DEV: /* Device error (see Note #1). */
case FS_ERR_DEV_IO:
case FS_ERR_DEV_TIMEOUT:
case FS_ERR_DEV_NOT_PRESENT:
APP_TRACE_DBG((" ...opened volume (unmounted).\r\n"));
return (DEF_FAIL);
case FS_ERR_PARTITION_NOT_FOUND: /* Volume error (see Note #2). */
APP_TRACE_DBG((" ...opened device (not formatted).\r\n"));
#if (FS_CFG_RD_ONLY_EN == DEF_DISABLED)
FSVol_Fmt("sd:0:", (void *)0, &err);
#endif
if (err == FS_ERR_NONE) {
APP_TRACE_DBG((" ...format completed.\r\n"));
} else {
APP_TRACE_DBG((" ...format failed.\r\n"));
return (DEF_FAIL);
}
break;
default:
APP_TRACE_DBG((" ...opening volume failed w/err = %d.\r\n\r\n", err));
return (DEF_FAIL);
}
return (DEF_OK);
}
#endif
/*
*********************************************************************************************************
* ENABLE END
*********************************************************************************************************
*/
#endif
|
MIPS/CI20_chromiumos_chromiumos-overlay
|
app-benchmarks/bootchart/files/bootchart-collector.c
|
<reponame>MIPS/CI20_chromiumos_chromiumos-overlay
/* bootchart-collector
*
* Copyright © 2009 Canonical Ltd.
* Author: <NAME> <<EMAIL>>.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <assert.h>
#include <dirent.h>
#include <limits.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BUFSIZE 524288
int append_buf (const char *str, size_t len,
int outfd, char *outbuf, size_t *outlen);
int copy_buf (int fd, int outfd, char *outbuf, size_t *outlen);
int flush_buf (int outfd, char *outbuf, size_t *outlen);
int read_file (int fd, const char *uptime, size_t uptimelen,
int outfd, char *outbuf, size_t *outlen);
int read_proc (DIR *proc, const char *uptime, size_t uptimelen,
int outfd, char *outbuf, size_t *outlen);
unsigned long get_uptime (int fd);
void sig_handler (int signum);
int
append_buf (const char *str,
size_t len,
int outfd,
char *outbuf,
size_t *outlen)
{
assert (len <= BUFSIZE);
if (*outlen + len > BUFSIZE)
if (flush_buf (outfd, outbuf, outlen) < 0)
return -1;
memcpy (outbuf + *outlen, str, len);
*outlen += len;
return 0;
}
int
copy_buf (int fd,
int outfd,
char *outbuf,
size_t *outlen)
{
for (;;) {
ssize_t len;
if (*outlen == BUFSIZE)
if (flush_buf (outfd, outbuf, outlen) < 0)
return -1;
len = read (fd, outbuf + *outlen, BUFSIZE - *outlen);
if (len < 0) {
perror ("read");
return -1;
} else if (len == 0)
break;
*outlen += len;
}
return 0;
}
int
flush_buf (int outfd,
char *outbuf,
size_t *outlen)
{
size_t writelen = 0;
while (writelen < *outlen) {
ssize_t len;
len = write (outfd, outbuf + writelen, *outlen - writelen);
if (len < 0) {
perror ("write");
exit (1);
}
writelen += len;
}
*outlen = 0;
return 0;
}
int
read_file (int fd,
const char *uptime,
size_t uptimelen,
int outfd,
char *outbuf,
size_t *outlen)
{
lseek (fd, SEEK_SET, 0);
if (append_buf (uptime, uptimelen, outfd, outbuf, outlen) < 0)
return -1;
if (copy_buf (fd, outfd, outbuf, outlen) < 0)
return -1;
if (append_buf ("\n", 1, outfd, outbuf, outlen) < 0)
return -1;
return 0;
}
int
read_proc (DIR *proc,
const char *uptime,
size_t uptimelen,
int outfd,
char *outbuf,
size_t *outlen)
{
struct dirent *ent;
rewinddir (proc);
if (append_buf (uptime, uptimelen, outfd, outbuf, outlen) < 0)
return -1;
while ((ent = readdir (proc)) != NULL) {
char filename[PATH_MAX];
int fd;
if ((ent->d_name[0] < '0') || (ent->d_name[0] > '9'))
continue;
sprintf (filename, "/proc/%s/stat", ent->d_name);
fd = open (filename, O_RDONLY);
if (fd < 0)
continue;
if (copy_buf (fd, outfd, outbuf, outlen) < 0)
;
if (close (fd) < 0)
continue;
}
if (append_buf ("\n", 1, outfd, outbuf, outlen) < 0)
return -1;
return 0;
}
unsigned long
get_uptime (int fd)
{
char buf[80];
ssize_t len;
unsigned long u1, u2;
lseek (fd, SEEK_SET, 0);
len = read (fd, buf, sizeof buf);
if (len < 0) {
perror ("read");
return 0;
}
buf[len] = '\0';
if (sscanf (buf, "%lu.%lu", &u1, &u2) != 2) {
perror ("sscanf");
return 0;
}
return u1 * 100 + u2;
}
void
sig_handler (int signum)
{
}
int
main (int argc,
char *argv[])
{
struct sigaction act;
sigset_t mask, oldmask;
struct rlimit rlim;
struct timespec timeout;
const char *output_dir = ".";
char filename[PATH_MAX];
int sfd, dfd, ufd;
DIR *proc;
int statfd, diskfd, procfd;
char statbuf[BUFSIZE], diskbuf[BUFSIZE], procbuf[BUFSIZE];
size_t statlen = 0, disklen = 0, proclen = 0;
unsigned long reltime = 0;
int arg = 1, rel = 0;
if ((argc > arg) && (! strcmp (argv[arg], "-r"))) {
rel = 1;
arg++;
}
if (argc <= arg) {
fprintf (stderr, "Usage: %s [-r] HZ [DIR]\n", argv[0]);
exit (1);
}
if (argc > arg) {
unsigned long hz;
char *endptr;
hz = strtoul (argv[arg], &endptr, 10);
if (*endptr) {
fprintf (stderr, "%s: HZ not an integer\n", argv[0]);
exit (1);
}
if (hz > 1) {
timeout.tv_sec = 0;
timeout.tv_nsec = 1000000000 / hz;
} else {
timeout.tv_sec = 1;
timeout.tv_nsec = 0;
}
arg++;
}
if (argc > arg) {
output_dir = argv[arg];
arg++;
}
sigemptyset (&mask);
sigaddset (&mask, SIGTERM);
sigaddset (&mask, SIGINT);
if (sigprocmask (SIG_BLOCK, &mask, &oldmask) < 0) {
perror ("sigprocmask");
exit (1);
}
act.sa_handler = sig_handler;
act.sa_flags = 0;
sigemptyset (&act.sa_mask);
if (sigaction (SIGTERM, &act, NULL) < 0) {
perror ("sigaction SIGTERM");
exit (1);
}
if (sigaction (SIGINT, &act, NULL) < 0) {
perror ("sigaction SIGINT");
exit (1);
}
/* Drop cores if we go wrong */
if (chdir ("/"))
;
rlim.rlim_cur = RLIM_INFINITY;
rlim.rlim_max = RLIM_INFINITY;
setrlimit (RLIMIT_CORE, &rlim);
proc = opendir ("/proc");
if (! proc) {
perror ("opendir /proc");
exit (1);
}
sfd = open ("/proc/stat", O_RDONLY);
if (sfd < 0) {
perror ("open /proc/stat");
exit (1);
}
dfd = open ("/proc/diskstats", O_RDONLY);
if (dfd < 0) {
perror ("open /proc/diskstats");
exit (1);
}
ufd = open ("/proc/uptime", O_RDONLY);
if (ufd < 0) {
perror ("open /proc/uptime");
exit (1);
}
sprintf (filename, "%s/proc_stat.log", output_dir);
statfd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (statfd < 0) {
perror ("open proc_stat.log");
exit (1);
}
sprintf (filename, "%s/proc_diskstats.log", output_dir);
diskfd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (diskfd < 0) {
perror ("open proc_diskstats.log");
exit (1);
}
sprintf (filename, "%s/proc_ps.log", output_dir);
procfd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (procfd < 0) {
perror ("open proc_ps.log");
exit (1);
}
if (rel) {
reltime = get_uptime (ufd);
if (! reltime)
exit (1);
}
for (;;) {
char uptime[80];
size_t uptimelen;
unsigned long u;
u = get_uptime (ufd);
if (! u)
exit (1);
uptimelen = sprintf (uptime, "%lu\n", u - reltime);
if (read_file (sfd, uptime, uptimelen,
statfd, statbuf, &statlen) < 0)
exit (1);
if (read_file (dfd, uptime, uptimelen,
diskfd, diskbuf, &disklen) < 0)
exit (1);
if (read_proc (proc, uptime, uptimelen,
procfd, procbuf, &proclen) < 0)
exit (1);
if (pselect (0, NULL, NULL, NULL, &timeout, &oldmask) < 0) {
if (errno == EINTR) {
break;
} else {
perror ("pselect");
exit (1);
}
}
}
if (flush_buf (statfd, statbuf, &statlen) < 0)
exit (1);
if (close (statfd) < 0) {
perror ("close proc_stat.log");
exit (1);
}
if (flush_buf (diskfd, diskbuf, &disklen) < 0)
exit (1);
if (close (diskfd) < 0) {
perror ("close proc_diskstats.log");
exit (1);
}
if (flush_buf (procfd, procbuf, &proclen) < 0)
exit (1);
if (close (procfd) < 0) {
perror ("close proc_ps.log");
exit (1);
}
if (close (ufd) < 0) {
perror ("close /proc/uptime");
exit (1);
}
if (close (dfd) < 0) {
perror ("close /proc/diskstats");
exit (1);
}
if (close (sfd) < 0) {
perror ("close /proc/stat");
exit (1);
}
if (closedir (proc) < 0) {
perror ("close /proc");
exit (1);
}
return 0;
}
|
MIPS/CI20_chromiumos_chromiumos-overlay
|
app-emulation/qemu-binfmt-wrapper/files/qemu-binfmt-wrapper.c
|
<filename>app-emulation/qemu-binfmt-wrapper/files/qemu-binfmt-wrapper.c
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Put a wrapper around qemu so that argv[0] is preserved when using binfmt_misc
// to execute custom binaries. Normally what happens is:
// - user runs ARM `ls`
// - kernel runs `/usr/bin/qemu-arm /bin/ls`
// - QEMU does its magic to emulate /bin/ls
// - the ls program is executed with argv[0]="/bin/ls"
// Most of the time this does not matter. But in some cases, the program really
// needs its argv[0] to be exact (in cases where it is checked).
//
// When we enable the P flag to the binfmt_misc wrapper, the situation is:
// - user runs ARM `ls`
// - kernel runs `/usr/bin/qemu-arm /bin/ls ls`
// - QEMU does its magic to emulate /bin/ls
// - the ls program is executed with argv[0]="/bin/ls" argv[1]="ls"
// See /usr/src/linux/Documentation/binfmt_misc.txt for details on the P flag.
//
// But when we deploy this wrapper, we get:
// - user runs ARM `ls`
// - kernel runs `/usr/bin/qemu-arm-binfmt-wrapper /bin/ls ls`
// - wrapper runs `/usr/bin/qemu-arm -0 ls /bin/ls`
// - QEMU does its magic to emulate /bin/ls
// - the ls program is executed with argv[0]="ls"
//
// Ideally QEMU should be able to handle this itself, but today it cannot.
#define _GNU_SOURCE
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int ret;
char **qargv;
// If we don't have the min # of args, then the user is probably poking
// us, so dump a message. The code below assumes we have at least 3 as
// that is what the P binfmt_misc flag will provide.
if (argc < 3) {
fprintf(stderr, "%s: do not execute directly; run through binfmt_misc\n",
basename(argv[0]));
return 1;
}
// Make space for the new argv. It'll be argv but with -0 and NULL.
qargv = malloc(sizeof(*argv) * (argc + 2));
// Reformat the argv[0] of the wrapper to point to the real QEMU.
// We assume it'll be `/usr/bin/qemu-arm-binfmt-wrapper`, so we just
// chop off the trailing "-binfmt-wrapper" to get `/usr/bin/qemu-arm`.
qargv[0] = strdup(argv[0]);
// This math is correct as sizeof("str") counts the \0.
qargv[0][strlen(argv[0]) - sizeof("binfmt-wrapper")] = '\0';
// Set qargv[1] to -0, load qargv[2] with the original argv[0] that
// the kernel has passed to us, and then set qargv[3] with the full
// path to the program we want to actually interpret.
// {/bin/ls, ls} -> {-0, ls, /bin/ls}
qargv[1] = "-0";
qargv[2] = argv[2];
qargv[3] = argv[1];
// Now copy over the remaining args untouched. We also copy the sentinel
// NULL which is why the argc math is like this.
memcpy(&qargv[4], &argv[3], (argc - 3 + 1) * sizeof(*argv));
ret = execv(qargv[0], qargv);
printf("%s: failed to exec %s: %m\n", argv[0], qargv[0]);
return ret;
}
|
MIPS/CI20_chromiumos_chromiumos-overlay
|
sys-libs/glibc/files/2.20/glibc-2.20-gentoo-stack_chk_fail.c
|
#define GENTOO_SSP_HANDLER
#include <debug/chk_fail.c>
|
MIPS/CI20_chromiumos_chromiumos-overlay
|
net-misc/modemmanager-classic-interfaces/files/mm-modem.h
|
<reponame>MIPS/CI20_chromiumos_chromiumos-overlay
/* Generated Header file do not edit */
/* ModemManager D-Bus Interface Specification */
/*
* version 0.5
*/
#define MM_MODEMMANAGER_PATH "/org/freedesktop/ModemManager"
#define MM_MODEMMANAGER_SERVICE "org.freedesktop.ModemManager"
/**************
* Interfaces *
**************/
#define MM_MODEMMANAGER_INTERFACE "org.freedesktop.ModemManager"
#define MM_MODEM_INTERFACE "org.freedesktop.ModemManager.Modem"
#define MM_MODEM_SIMPLE_INTERFACE "org.freedesktop.ModemManager.Modem.Simple"
#define MM_MODEM_CDMA_INTERFACE "org.freedesktop.ModemManager.Modem.Cdma"
#define MM_MODEM_GSM_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm"
#define MM_MODEM_GSM_CARD_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Card"
#define MM_MODEM_GSM_CONTACTS_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Contacts"
#define MM_MODEM_GSM_HSO_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Hso"
#define MM_MODEM_GSM_NETWORK_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Network"
#define MM_MODEM_GSM_SMS_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.SMS"
#define MM_MODEM_GSM_USSD_INTERFACE "org.freedesktop.ModemManager.Modem.Gsm.Ussd"
#define MM_MODEM_FIRMWARE_INTERFACE "org.freedesktop.ModemManager.Modem.Firmware"
#define MM_MODEM_LOCATION_INTERFACE "org.freedesktop.ModemManager.Modem.Location"
#define MM_MODEM_TIME_INTERFACE "org.freedesktop.ModemManager.Modem.Time"
#define MM_DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
/***********************
* Methods/Enums/Flags *
***********************/
/*
* Interface org.freedesktop.ModemManager
*/
#define MM_MANAGER_METHOD_ENUMERATEDEVICES "EnumerateDevices"
#define MM_MANAGER_METHOD_SCANDEVICES "ScanDevices"
#define MM_MANAGER_METHOD_SETLOGGING "SetLogging"
#define MM_MANAGER_SIGNAL_DEVICEADDED "DeviceAdded"
#define MM_MANAGER_SIGNAL_DEVICEREMOVED "DeviceRemoved"
/*
* Interface org.freedesktop.ModemManager.Modem
*/
#define MM_MODEM_METHOD_ENABLE "Enable"
#define MM_MODEM_METHOD_CONNECT "Connect"
#define MM_MODEM_METHOD_DISCONNECT "Disconnect"
#define MM_MODEM_METHOD_GETIP4CONFIG "GetIP4Config"
#define MM_MODEM_METHOD_GETINFO "GetInfo"
#define MM_MODEM_METHOD_RESET "Reset"
#define MM_MODEM_METHOD_FACTORYRESET "FactoryReset"
#define MM_MODEM_SIGNAL_STATECHANGED "StateChanged"
/* MM_MODEM_TYPE enum values */
#define MM_MODEM_TYPE_GSM 1
#define MM_MODEM_TYPE_CDMA 2
/* MM_MODEM_IP_METHOD enum values */
#define MM_MODEM_IP_METHOD_PPP 0
#define MM_MODEM_IP_METHOD_STATIC 1
#define MM_MODEM_IP_METHOD_DHCP 2
/* MM_MODEM_STATE_CHANGED_REASON enum values */
#define MM_MODEM_STATE_CHANGED_REASON_UNKNOWN 0
#define MM_MODEM_STATE_CHANGED_REASON_USER_REQUESTED 1
#define MM_MODEM_STATE_CHANGED_REASON_SUSPEND 2
/*
* Interface org.freedesktop.ModemManager.Modem.Simple
*/
#define MM_MODEM_SIMPLE_METHOD_CONNECT "Connect"
#define MM_MODEM_SIMPLE_METHOD_GETSTATUS "GetStatus"
/*
* Interface org.freedesktop.ModemManager.Modem.Cdma
*/
#define MM_MODEM_CDMA_METHOD_ACTIVATE "Activate"
#define MM_MODEM_CDMA_METHOD_ACTIVATEMANUAL "ActivateManual"
#define MM_MODEM_CDMA_METHOD_ACTIVATEMANUALDEBUG "ActivateManualDebug"
#define MM_MODEM_CDMA_METHOD_GETSIGNALQUALITY "GetSignalQuality"
#define MM_MODEM_CDMA_METHOD_GETESN "GetEsn"
#define MM_MODEM_CDMA_METHOD_GETSERVINGSYSTEM "GetServingSystem"
#define MM_MODEM_CDMA_METHOD_GETREGISTRATIONSTATE "GetRegistrationState"
#define MM_MODEM_CDMA_SIGNAL_ACTIVATIONSTATECHANGED "ActivationStateChanged"
#define MM_MODEM_CDMA_SIGNAL_SIGNALQUALITY "SignalQuality"
#define MM_MODEM_CDMA_SIGNAL_REGISTRATIONSTATECHANGED "RegistrationStateChanged"
/* MM_MODEM_CDMA_REGISTRATION_STATE enum values */
#define MM_MODEM_CDMA_REGISTRATION_STATE_UNKNOWN 0
#define MM_MODEM_CDMA_REGISTRATION_STATE_REGISTERED 1
#define MM_MODEM_CDMA_REGISTRATION_STATE_HOME 2
#define MM_MODEM_CDMA_REGISTRATION_STATE_ROAMING 3
/* MM_MODEM_CDMA_ACTIVATION_STATE enum values */
#define MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED 0
#define MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATING 1
#define MM_MODEM_CDMA_ACTIVATION_STATE_PARTIALLY_ACTIVATED 2
#define MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED 3
/* MM_MODEM_CDMA_ACTIVATION_ERROR enum values */
#define MM_MODEM_CDMA_ACTIVATION_ERROR_NO_ERROR 0
#define MM_MODEM_CDMA_ACTIVATION_ERROR_ROAMING 1
#define MM_MODEM_CDMA_ACTIVATION_ERROR_WRONG_RADIO_INTERFACE 2
#define MM_MODEM_CDMA_ACTIVATION_ERROR_COULD_NOT_CONNECT 3
#define MM_MODEM_CDMA_ACTIVATION_ERROR_SECURITY_AUTHENTICATION_FAILED 4
#define MM_MODEM_CDMA_ACTIVATION_ERROR_PROVISIONING_FAILED 5
#define MM_MODEM_CDMA_ACTIVATION_ERROR_NO_SIGNAL 6
#define MM_MODEM_CDMA_ACTIVATION_ERROR_UNKNOWN 7
#define MM_MODEM_CDMA_ACTIVATION_ERROR_TIMED_OUT 8
#define MM_MODEM_CDMA_ACTIVATION_ERROR_START_FAILED 9
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm
*/
/* MM_MODEM_GSM_ALLOWED_MODE enum values */
#define MM_MODEM_GSM_ALLOWED_MODE_ANY 0
#define MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED 1
#define MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED 2
#define MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY 3
#define MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY 4
/* MM_MODEM_GSM_ACCESS_TECH enum values */
#define MM_MODEM_GSM_ACCESS_TECH_UNKNOWN 0
#define MM_MODEM_GSM_ACCESS_TECH_GSM 1
#define MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT 2
#define MM_MODEM_GSM_ACCESS_TECH_GPRS 3
#define MM_MODEM_GSM_ACCESS_TECH_EDGE 4
#define MM_MODEM_GSM_ACCESS_TECH_UMTS 5
#define MM_MODEM_GSM_ACCESS_TECH_HSDPA 6
#define MM_MODEM_GSM_ACCESS_TECH_HSUPA 7
#define MM_MODEM_GSM_ACCESS_TECH_HSPA 8
#define MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS 9
/* MM_MODEM_GSM_MODE flag values */
#define MM_MODEM_GSM_MODE_UNKNOWN 0x0
#define MM_MODEM_GSM_MODE_ANY 0x1
#define MM_MODEM_GSM_MODE_GPRS 0x2
#define MM_MODEM_GSM_MODE_EDGE 0x4
#define MM_MODEM_GSM_MODE_UMTS 0x8
#define MM_MODEM_GSM_MODE_HSDPA 0x10
#define MM_MODEM_GSM_MODE_2G_PREFERRED 0x20
#define MM_MODEM_GSM_MODE_3G_PREFERRED 0x40
#define MM_MODEM_GSM_MODE_2G_ONLY 0x80
#define MM_MODEM_GSM_MODE_3G_ONLY 0x100
#define MM_MODEM_GSM_MODE_HSUPA 0x200
#define MM_MODEM_GSM_MODE_HSPA 0x400
#define MM_MODEM_GSM_MODE_GSM 0x800
#define MM_MODEM_GSM_MODE_GSM_COMPACT 0x1000
/* MM_MODEM_GSM_BAND flag values */
#define MM_MODEM_GSM_BAND_UNKNOWN 0x0
#define MM_MODEM_GSM_BAND_ANY 0x1
#define MM_MODEM_GSM_BAND_EGSM 0x2
#define MM_MODEM_GSM_BAND_DCS 0x4
#define MM_MODEM_GSM_BAND_PCS 0x8
#define MM_MODEM_GSM_BAND_G850 0x10
#define MM_MODEM_GSM_BAND_U2100 0x20
#define MM_MODEM_GSM_BAND_U1800 0x40
#define MM_MODEM_GSM_BAND_U17IV 0x80
#define MM_MODEM_GSM_BAND_U800 0x100
#define MM_MODEM_GSM_BAND_U850 0x200
#define MM_MODEM_GSM_BAND_U900 0x400
#define MM_MODEM_GSM_BAND_U17IX 0x800
#define MM_MODEM_GSM_BAND_U1900 0x1000
#define MM_MODEM_GSM_BAND_U2600 0x2000
/* MM_MODEM_GSM_FACILITY flag values */
#define MM_MODEM_GSM_FACILITY_NONE 0x0
#define MM_MODEM_GSM_FACILITY_SIM 0x1
#define MM_MODEM_GSM_FACILITY_FIXED_DIALING 0x2
#define MM_MODEM_GSM_FACILITY_PH_SIM 0x4
#define MM_MODEM_GSM_FACILITY_PH_FSIM 0x8
#define MM_MODEM_GSM_FACILITY_NET_PERS 0x10
#define MM_MODEM_GSM_FACILITY_NET_SUB_PERS 0x20
#define MM_MODEM_GSM_FACILITY_PROVIDER_PERS 0x40
#define MM_MODEM_GSM_FACILITY_CORP_PERS 0x80
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm.Card
*/
#define MM_MODEM_GSM_CARD_METHOD_GETIMEI "GetImei"
#define MM_MODEM_GSM_CARD_METHOD_GETIMSI "GetImsi"
#define MM_MODEM_GSM_CARD_METHOD_GETOPERATORID "GetOperatorId"
#define MM_MODEM_GSM_CARD_METHOD_GETSPN "GetSpn"
#define MM_MODEM_GSM_CARD_METHOD_GETMSISDN "GetMsIsdn"
#define MM_MODEM_GSM_CARD_METHOD_SENDPUK "SendPuk"
#define MM_MODEM_GSM_CARD_METHOD_SENDPIN "SendPin"
#define MM_MODEM_GSM_CARD_METHOD_ENABLEPIN "EnablePin"
#define MM_MODEM_GSM_CARD_METHOD_CHANGEPIN "ChangePin"
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm.Contacts
*/
#define MM_MODEM_GSM_CONTACTS_METHOD_ADD "Add"
#define MM_MODEM_GSM_CONTACTS_METHOD_DELETE "Delete"
#define MM_MODEM_GSM_CONTACTS_METHOD_GET "Get"
#define MM_MODEM_GSM_CONTACTS_METHOD_LIST "List"
#define MM_MODEM_GSM_CONTACTS_METHOD_FIND "Find"
#define MM_MODEM_GSM_CONTACTS_METHOD_GETCOUNT "GetCount"
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm.Hso
*/
#define MM_MODEM_GSM_HSO_METHOD_AUTHENTICATE "Authenticate"
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm.Network
*/
#define MM_MODEM_GSM_NETWORK_METHOD_REGISTER "Register"
#define MM_MODEM_GSM_NETWORK_METHOD_SCAN "Scan"
#define MM_MODEM_GSM_NETWORK_METHOD_SETAPN "SetApn"
#define MM_MODEM_GSM_NETWORK_METHOD_GETSIGNALQUALITY "GetSignalQuality"
#define MM_MODEM_GSM_NETWORK_METHOD_SETBAND "SetBand"
#define MM_MODEM_GSM_NETWORK_METHOD_GETBAND "GetBand"
#define MM_MODEM_GSM_NETWORK_METHOD_SETNETWORKMODE "SetNetworkMode"
#define MM_MODEM_GSM_NETWORK_METHOD_GETNETWORKMODE "GetNetworkMode"
#define MM_MODEM_GSM_NETWORK_METHOD_GETREGISTRATIONINFO "GetRegistrationInfo"
#define MM_MODEM_GSM_NETWORK_METHOD_SETALLOWEDMODE "SetAllowedMode"
#define MM_MODEM_GSM_NETWORK_SIGNAL_SIGNALQUALITY "SignalQuality"
#define MM_MODEM_GSM_NETWORK_SIGNAL_REGISTRATIONINFO "RegistrationInfo"
#define MM_MODEM_GSM_NETWORK_SIGNAL_NETWORKMODE "NetworkMode"
/* MM_MODEM_GSM_NETWORK_REG_STATUS enum values */
#define MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE 0
#define MM_MODEM_GSM_NETWORK_REG_STATUS_HOME 1
#define MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING 2
#define MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED 3
#define MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN 4
#define MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING 5
/* MM_MODEM_GSM_NETWORK_DEPRECATED_MODE enum values */
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_ANY 0
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_GPRS 1
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_EDGE 2
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_UMTS 3
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSDPA 4
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_PREFERRED 5
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_PREFERRED 6
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_ONLY 7
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_ONLY 8
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSUPA 9
#define MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_HSPA 10
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm.SMS
*/
#define MM_MODEM_GSM_SMS_METHOD_DELETE "Delete"
#define MM_MODEM_GSM_SMS_METHOD_GET "Get"
#define MM_MODEM_GSM_SMS_METHOD_GETFORMAT "GetFormat"
#define MM_MODEM_GSM_SMS_METHOD_SETFORMAT "SetFormat"
#define MM_MODEM_GSM_SMS_METHOD_GETSMSC "GetSmsc"
#define MM_MODEM_GSM_SMS_METHOD_SETSMSC "SetSmsc"
#define MM_MODEM_GSM_SMS_METHOD_LIST "List"
#define MM_MODEM_GSM_SMS_METHOD_SAVE "Save"
#define MM_MODEM_GSM_SMS_METHOD_SEND "Send"
#define MM_MODEM_GSM_SMS_METHOD_SENDFROMSTORAGE "SendFromStorage"
#define MM_MODEM_GSM_SMS_METHOD_SETINDICATION "SetIndication"
#define MM_MODEM_GSM_SMS_SIGNAL_SMSRECEIVED "SmsReceived"
#define MM_MODEM_GSM_SMS_SIGNAL_COMPLETED "Completed"
/*
* Interface org.freedesktop.ModemManager.Modem.Gsm.Ussd
*/
#define MM_MODEM_GSM_USSD_METHOD_INITIATE "Initiate"
#define MM_MODEM_GSM_USSD_METHOD_RESPOND "Respond"
#define MM_MODEM_GSM_USSD_METHOD_CANCEL "Cancel"
/*
* Interface org.freedesktop.ModemManager.Modem.Firmware
*/
#define MM_MODEM_FIRMWARE_METHOD_LIST "List"
#define MM_MODEM_FIRMWARE_METHOD_SELECT "Select"
#define MM_MODEM_FIRMWARE_METHOD_INSTALL "Install"
/*
* Interface org.freedesktop.ModemManager.Modem.Location
*/
#define MM_MODEM_LOCATION_METHOD_ENABLE "Enable"
#define MM_MODEM_LOCATION_METHOD_GETLOCATION "GetLocation"
/* MM_MODEM_LOCATION_CAPABILITIES flag values */
#define MM_MODEM_LOCATION_CAPABILITY_UNKNOWN 0x0
#define MM_MODEM_LOCATION_CAPABILITY_GPS_NMEA 0x1
#define MM_MODEM_LOCATION_CAPABILITY_GSM_LAC_CI 0x2
#define MM_MODEM_LOCATION_CAPABILITY_GPS_RAW 0x4
/*
* Interface org.freedesktop.ModemManager.Modem.Time
*/
#define MM_MODEM_TIME_METHOD_GETNETWORKTIME "GetNetworkTime"
#define MM_MODEM_TIME_SIGNAL_NETWORKTIMECHANGED "NetworkTimeChanged"
/*
* Interface org.freedesktop.DBus.Properties
*/
#define MM_MANAGER_SIGNAL_MMPROPERTIESCHANGED "MmPropertiesChanged"
#define MM_MANAGER_SIGNAL_PROPERTIESCHANGED "PropertiesChanged"
/**********
* Errors *
**********/
#define MM_ERROR_MODEM_SERIALOPENFAILED "SerialOpenFailed"
#define MM_ERROR_MODEM_SERIALSENDFAILED "SerialSendFailed"
#define MM_ERROR_MODEM_SERIALRESPONSETIMEOUT "SerialResponseTimeout"
#define MM_ERROR_MODEM_GENERAL "General"
#define MM_ERROR_MODEM_OPERATIONNOTSUPPORTED "OperationNotSupported"
#define MM_ERROR_MODEM_CONNECTED "Connected"
#define MM_ERROR_MODEM_DISCONNECTED "Disconnected"
#define MM_ERROR_MODEM_OPERATIONINPROGRESS "OperationInProgress"
#define MM_ERROR_MODEM_NOCARRIER "NoCarrier"
#define MM_ERROR_MODEM_NODIALTONE "NoDialtone"
#define MM_ERROR_MODEM_BUSY "Busy"
#define MM_ERROR_MODEM_NOANSWER "NoAnswer"
#define MM_ERROR_MODEM_GSM_PHONEFAILURE "PhoneFailure"
#define MM_ERROR_MODEM_GSM_NOCONNECTION "NoConnection"
#define MM_ERROR_MODEM_GSM_LINKRESERVED "LinkReserved"
#define MM_ERROR_MODEM_GSM_OPERATIONNOTALLOWED "OperationNotAllowed"
#define MM_ERROR_MODEM_GSM_OPERATIONNOTSUPPORTED "OperationNotSupported"
#define MM_ERROR_MODEM_GSM_PHSIMPINREQUIRED "PhSimPinRequired"
#define MM_ERROR_MODEM_GSM_PHFSIMPINREQUIRED "PhFSimPinRequired"
#define MM_ERROR_MODEM_GSM_PHFSIMPUKREQUIRED "PhFSimPukRequired"
#define MM_ERROR_MODEM_GSM_SIMNOTINSERTED "SimNotInserted"
#define MM_ERROR_MODEM_GSM_SIMPINREQUIRED "SimPinRequired"
#define MM_ERROR_MODEM_GSM_SIMPUKREQUIRED "SimPukRequired"
#define MM_ERROR_MODEM_GSM_SIMFAILURE "SimFailure"
#define MM_ERROR_MODEM_GSM_SIMBUSY "SimBusy"
#define MM_ERROR_MODEM_GSM_SIMWRONG "SimWrong"
#define MM_ERROR_MODEM_GSM_INCORRECTPASSWORD "IncorrectPassword"
#define MM_ERROR_MODEM_GSM_SIMPIN2REQUIRED "SimPin2Required"
#define MM_ERROR_MODEM_GSM_SIMPUK2REQUIRED "SimPuk2Required"
#define MM_ERROR_MODEM_GSM_MEMORYFULL "MemoryFull"
#define MM_ERROR_MODEM_GSM_INVALIDINDEX "InvalidIndex"
#define MM_ERROR_MODEM_GSM_NOTFOUND "NotFound"
#define MM_ERROR_MODEM_GSM_MEMORYFAILURE "MemoryFailure"
#define MM_ERROR_MODEM_GSM_TEXTTOOLONG "TextTooLong"
#define MM_ERROR_MODEM_GSM_INVALIDCHARS "InvalidChars"
#define MM_ERROR_MODEM_GSM_DIALSTRINGTOOLONG "DialStringTooLong"
#define MM_ERROR_MODEM_GSM_INVALIDDIALSTRING "InvalidDialString"
#define MM_ERROR_MODEM_GSM_NONETWORK "NoNetwork"
#define MM_ERROR_MODEM_GSM_NETWORKTIMEOUT "NetworkTimeout"
#define MM_ERROR_MODEM_GSM_NETWORKNOTALLOWED "NetworkNotAllowed"
#define MM_ERROR_MODEM_GSM_NETWORKPINREQUIRED "NetworkPinRequired"
#define MM_ERROR_MODEM_GSM_NETWORKPUKREQUIRED "NetworkPukRequired"
#define MM_ERROR_MODEM_GSM_NETWORKSUBSETPINREQUIRED "NetworkSubsetPinRequired"
#define MM_ERROR_MODEM_GSM_NETWORKSUBSETPUKREQUIRED "NetworkSubsetPukRequired"
#define MM_ERROR_MODEM_GSM_SERVICEPINREQUIRED "ServicePinRequired"
#define MM_ERROR_MODEM_GSM_SERVICEPUKREQUIRED "ServicePukRequired"
#define MM_ERROR_MODEM_GSM_CORPORATEPINREQUIRED "CorporatePinRequired"
#define MM_ERROR_MODEM_GSM_CORPORATEPUKREQUIRED "CorporatePukRequired"
#define MM_ERROR_MODEM_GSM_HIDDENKEYREQUIRED "HiddenKeyRequired"
#define MM_ERROR_MODEM_GSM_EAPMETHODNOTSUPPORTED "EapMethodNotSupported"
#define MM_ERROR_MODEM_GSM_INCORRECTPARAMS "IncorrectParams"
#define MM_ERROR_MODEM_GSM_UNKNOWN "Unknown"
#define MM_ERROR_MODEM_GSM_GPRSILLEGALMS "GprsIllegalMs"
#define MM_ERROR_MODEM_GSM_GPRSILLEGALME "GprsIllegalMe"
#define MM_ERROR_MODEM_GSM_GPRSSERVICENOTALLOWED "GprsServiceNotAllowed"
#define MM_ERROR_MODEM_GSM_GPRSPLMNNOTALLOWED "GprsPlmnNotAllowed"
#define MM_ERROR_MODEM_GSM_GPRSLOCATIONNOTALLOWED "GprsLocationNotAllowed"
#define MM_ERROR_MODEM_GSM_GPRSROAMINGNOTALLOWED "GprsRoamingNotAllowed"
#define MM_ERROR_MODEM_GSM_GPRSOPTIONNOTSUPPORTED "GprsOptionNotSupported"
#define MM_ERROR_MODEM_GSM_GPRSNOTSUBSCRIBED "GprsNotSubscribed"
#define MM_ERROR_MODEM_GSM_GPRSOUTOFORDER "GprsOutOfOrder"
#define MM_ERROR_MODEM_GSM_GPRSPDPAUTHFAILURE "GprsPdpAuthFailure"
#define MM_ERROR_MODEM_GSM_GPRSUNSPECIFIED "GprsUnspecified"
#define MM_ERROR_MODEM_GSM_GPRSINVALIDCLASS "GprsInvalidClass"
|
keith/Github-Status
|
Github Status/KSConstants.h
|
//
// KSConstants.h
// Github Status
//
// Created by <NAME> on 12/10/12.
// Copyright (c) 2012 <NAME>. All rights reserved.
//
FOUNDATION_EXPORT NSString * const KSGithubStatusOpenAtLogin;
FOUNDATION_EXPORT NSString * const KSGithubStatusRefreshInterval;
FOUNDATION_EXPORT NSString * const KSGithubStatusDownRefreshInterval;
|
keith/Github-Status
|
Github Status/NSUserNotificationCenter+KSNotifications.h
|
//
// NSUserNotificationCenter+KSNotifications.h
// Github Status
//
// Created by <NAME> on 7/18/14.
// Copyright (c) 2014 <NAME>. All rights reserved.
//
@interface NSUserNotificationCenter (KSNotifications)
- (void)ks_deliverNotificationWithText:(NSString *)text;
@end
|
keith/Github-Status
|
Github Status/KSMenuManager.h
|
//
// KSMenuManager.h
// Github Status
//
// Created by <NAME> on 7/18/14.
// Copyright (c) 2014 <NAME>. All rights reserved.
//
@interface KSMenuManager : NSObject
@property (nonatomic) NSMenu *menu;
- (void)setLastCheckedReadableDateString:(NSString *)dateString;
- (void)setGithubStatusString:(NSString *)status;
- (void)setGithubMessageString:(NSString *)message;
- (void)setGithubUpdatedAtDateString:(NSString *)dateString;
- (void)setRefreshTarget:(id)target;
- (void)setRefreshSelector:(SEL)selector;
@end
|
keith/Github-Status
|
Github Status/KSAppDelegate.h
|
//
// KSAppDelegate.h
// Github Status
//
// Created by <NAME> on 12/10/12.
// Copyright (c) 2012 <NAME>. All rights reserved.
//
@interface KSAppDelegate : NSObject <NSApplicationDelegate, NSUserNotificationCenterDelegate>
@end
|
keith/Github-Status
|
Github Status/KSStatusItemManager.h
|
//
// KSStatusItemManager.h
// Github Status
//
// Created by <NAME> on 7/18/14.
// Copyright (c) 2014 <NAME>. All rights reserved.
//
@interface KSStatusItemManager : NSObject
- (void)setStatusItemMenu:(NSMenu *)menu;
- (void)useNormalImage;
- (void)useWarningImage;
- (void)removeStatusItem;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/LineGraph.h
|
//
// LineGraph.h
// healthManagement
//
// Created by Eason on 2017/3/15.
// Copyright © 2017年 eason. All rights reserved.
//
#import "CommonDiagram.h"
@interface LineGraph :CommonDiagram
/**
转换源数据为float
@param itemValue 元数据
@return float数据
*/
-(float)transformSoureItem:(id)itemValue;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/Model/PointCircularModel.h
|
//
// PointCircularModel.h
// healthManagement
//
// Created by Eason on 2017/3/16.
// Copyright © 2017年 eason. All rights reserved.
//
#import "LineDiagramModel.h"
#import <UIKit/UIKit.h>
@interface PointCircularModel : LineDiagramModel
@property (nonatomic, assign) float radius;
@property (nonatomic, strong) UIColor *color;
@end
|
WriteforBlack/YEToolsLib
|
Example/Pods/Target Support Files/YEToolsLib/YEToolsLib-umbrella.h
|
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#import "HToolsLibHeader.h"
#import "BaseNaviViewController.h"
#import "BaseTableViewDataSource.h"
#import "BaseViewController.h"
#import "BaseWebViewController.h"
#import "BaseWKWebViewController.h"
#import "Http.h"
#import "HttpHUD.h"
#import "HttpSupport.h"
#import "Reachability.h"
#import "BaseCellModel.h"
#import "BaseRefreshTableViewController.h"
#import "FileDirManager.h"
#import "NSData+Encryption.h"
#import "NSDate+Formatter.h"
#import "NSObject+PropertyToDict.h"
#import "NSString+Encryption.h"
#import "NSString+HtmlCompare.h"
#import "SysCommunication.h"
#import "UILabel+StringFrame.h"
#import "CircularProgressView.h"
#import "BaseDiagram.h"
#import "CommonDiagram.h"
#import "Histogram.h"
#import "LineGraph.h"
#import "LowHightHistogram.h"
#import "HistogramModel.h"
#import "LineDiagramModel.h"
#import "LowHeightHistogramModel.h"
#import "PointCircularModel.h"
#import "PointCircularGraph.h"
#import "AESEnryption.h"
#import "RNCryptor+Private.h"
#import "RNCryptor+Swift.h"
#import "RNCryptor.h"
#import "RNCryptorEngine.h"
#import "RNDecryptor.h"
#import "RNEncryptor.h"
FOUNDATION_EXPORT double YEToolsLibVersionNumber;
FOUNDATION_EXPORT const unsigned char YEToolsLibVersionString[];
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/CommonDiagram.h
|
//
// CommonDiagram.h
// healthManagement
//
// Created by Eason on 2017/3/15.
// Copyright © 2017年 eason. All rights reserved.
//
#import "BaseDiagram.h"
#import "LineDiagramModel.h"
#define TopMaxValueSpacePercent 0.1
@interface CommonDiagram : BaseDiagram
@property(nonatomic, strong) UIColor *fitColor; //填充颜色
@property(nonatomic, assign) CGFloat itemOffset; //偏移量
@property(nonatomic, assign) CGFloat maxY; //最高值
@property(nonatomic, readonly) NSArray *drawRectArray;//绘制的数据
@property(nonatomic, readonly) id sourceData; //源数据
/**
初始化
@param frame Frame
@param aFitColor 填充颜色
@param aBackGroundColor 背景色
@param aItemOffset 间距
@return 实例
*/
-(id)initWithFrame:(CGRect)frame fitColor:(UIColor*)aFitColor backGroundColor:(UIColor*)aBackGroundColor itemOffset:(CGFloat)aItemOffset;
/**
循环处理每个数据获得绘制model
@param itemValue 源数据某一项的值
@return 绘制model
*/
-(LineDiagramModel*)filter:(id)itemValue idx:(NSInteger)idx;
/**
过滤原始数据获取最大的绘制值
@return 最大绘制值
*/
-(float)filterSourceDataForMaxValue;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/HToolsLibHeader.h
|
//
// HToolsLibHeader.h
// Pods
//
// Created by Eason on 2017/4/7.
//
//
#ifndef HToolsLibHeader_h
#define HToolsLibHeader_h
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
//颜色
#define ColorWithRGBA(int_r,int_g,int_b,int_a) \
[UIColor colorWithRed:(int_r)/255.0 green:(int_g)/255.0 blue:(int_b)/255.0 alpha:(int_a)/255.0]
//通过数字初始化颜色
#define ColorWithNumberRGB(_hex) \
ColorWithRGBA(((_hex)>>16)&0xFF,((_hex)>>8)&0xFF,(_hex)&0xFF,255)
#define ColorWithNumberRGBA(_hex) \
ColorWithRGBA(((_hex)>>24)&0xFF,((_hex)>>16)&0xFF,((_hex)>>8)&0xFF,(_hex)&0xFF)
#endif /* HToolsLibHeader_h */
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/Base/net/Http.h
|
//
// Http.h
// healthManagement
//
// Created by Eason on 2017/3/10.
// Copyright © 2017年 eason. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <MJExtension/MJExtension.h> //字典和对象互相转换的第三方库
typedef void(^RESULT)(NSDictionary*result);
typedef void(^ERROR_H)(NSError *errorH);
@interface Http : NSObject
/**
Get请求解析json
@param host host
@param dict 参数
@param success 成功回调
@param errorH 失败回调
*/
-(void)get:(NSString*)host param:(NSDictionary*)dict success:(RESULT)success error:(ERROR_H)errorH;
/**
Post请求解析json
@param host host
@param dict 参数
@param success 成功回调
@param errorH 失败回调
*/
-(void)post:(NSString*)host param:(NSDictionary*)dict success:(RESULT)success error:(ERROR_H)errorH;
/**
附带文件的POST请求解析返回的json
@param host host
@param dict 参数
@param aFileData 文件数据
@param aFileName 文件名称 例如"image/jpg"、"image/png"
@param aType 文件类型
@param success 成功
@param errorH 失败
*/
-(void)postFile:(NSString*)host param:(NSDictionary*)dict fileData:(NSData*)aFileData fileName:(NSString*)aFileName type:(NSString*)aType success:(RESULT)success error:(ERROR_H)errorH;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/BaseDiagram.h
|
<gh_stars>0
//
// BaseDiagram.h
// healthManagement
//
// Created by Eason on 2017/3/15.
// Copyright © 2017年 eason. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface BaseDiagram : UIView
/**
设置源数据
@param source 源数据
*/
-(void)setSource:(id)source;
/**
设置画法
*/
-(void)drawingMethod;
//使用默认的重绘方式绘制
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/Histogram.h
|
<reponame>WriteforBlack/YEToolsLib
//
// Histogram.h
// healthManagement
//
// Created by Eason on 2017/3/15.
// Copyright © 2017年 eason. All rights reserved.
//
#import "LineGraph.h"
#import "HistogramModel.h"
@interface Histogram : LineGraph
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/LowHightHistogram.h
|
<gh_stars>0
//
// LowHightHistogram.h
// healthManagement
//
// Created by Eason on 2017/3/16.
// Copyright © 2017年 eason. All rights reserved.
//
#import "Histogram.h"
#import "LowHeightHistogramModel.h"
@interface LowHightHistogram : Histogram
/**
设置圆角大小
@param rectRadius 半径
*/
-(void)setRectRadius:(float)rectRadius;
@end
|
WriteforBlack/YEToolsLib
|
Example/YEToolsLib/YEAppDelegate.h
|
//
// YEAppDelegate.h
// YEToolsLib
//
// Created by WriteforBlack on 04/10/2017.
// Copyright (c) 2017 WriteforBlack. All rights reserved.
//
@import UIKit;
@interface YEAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/Model/HistogramModel.h
|
//
// HistogramModel.h
// healthManagement
//
// Created by Eason on 2017/3/16.
// Copyright © 2017年 eason. All rights reserved.
//
#import "LineDiagramModel.h"
@interface HistogramModel : LineDiagramModel
@property(nonatomic, assign) float dWidth;
@property(nonatomic, assign) float dHeight;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/PointCircularGraph.h
|
<reponame>WriteforBlack/YEToolsLib
//
// PointCircularGraph.h
// healthManagement
//
// Created by Eason on 2017/3/15.
// Copyright © 2017年 eason. All rights reserved.
//
#import "LineGraph.h"
#import "PointCircularModel.h"
@interface PointCircularGraph : LineGraph
/**
设置绘制小圆点的相关信息
@param radius 半径
@param aHighValue 高位值
@param ahighColor 高位颜色
*/
-(void)setPointRadius:(float)radius highValue:(float)aHighValue highColor:(UIColor*)ahighColor;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/CircularProgressView.h
|
//
// CircularProgressView.h
// healthManagement
//
// Created by yangxiaohui on 2017/3/14.
// Copyright © 2017年 yxh. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef enum DIRECTION{
DIRECTION_TOP_ACS = 0, // 从顶部顺时针转
DIRECTION_TOP_DESC, //从顶部逆时针转
DIRECTION_BOTTOM_ASC, //从底部顺时针转
DIRECTION_BOTTOM_DESC, //从底部逆时针转
}DIRECTION;
@interface CircularProgressView : UIView
@property(nonatomic ,strong) UIColor * LineColor; // 线条颜色
@property(nonatomic,strong) UIColor * backColor; // 线条背景色
@property(nonatomic ,assign) CGFloat completeNum;//进度
@property(nonatomic ,assign) NSInteger clockDirection;//转向
@property(nonatomic ,assign) BOOL isRound; // 圆弧形是否为圆角
@property(nonatomic,assign) CGFloat offset; // 偏移量(0~100)
// 绘制圆形进度条
-(void)drawRoundProgress;
- (instancetype)initWithFrame:(CGRect)frame lineColor:(UIColor *)lineColor completeNum:(CGFloat)num;
@end
|
WriteforBlack/YEToolsLib
|
Example/YEToolsLib/YEViewController.h
|
//
// YEViewController.h
// YEToolsLib
//
// Created by WriteforBlack on 04/10/2017.
// Copyright (c) 2017 WriteforBlack. All rights reserved.
//
@import UIKit;
@interface YEViewController : UIViewController
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/Model/LineDiagramModel.h
|
<filename>YEToolsLib/Classes/UIKit+YETools/Diagram/Model/LineDiagramModel.h<gh_stars>0
//
// LineDiagramModel.h
// healthManagement
//
// Created by Eason on 2017/3/16.
// Copyright © 2017年 eason. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface LineDiagramModel : NSObject
@property(nonatomic, assign) float dx;
@property(nonatomic, assign) float dy;
@end
|
WriteforBlack/YEToolsLib
|
YEToolsLib/Classes/UIKit+YETools/Diagram/Model/LowHeightHistogramModel.h
|
//
// LowHeightHistogramModel.h
// healthManagement
//
// Created by Eason on 2017/3/16.
// Copyright © 2017年 eason. All rights reserved.
//
#import "HistogramModel.h"
@interface LowHeightHistogramModel : HistogramModel
@property(nonatomic, assign) float lowDy;
@end
|
asiosldh/BMDragCellCollectionView
|
BMDragCellCollectionViewDemo/BMDragCellCollectionViewDemo/Demo/BMTodayHeadlinesDrag/BMTodayHeadlinesDragCell.h
|
<filename>BMDragCellCollectionViewDemo/BMDragCellCollectionViewDemo/Demo/BMTodayHeadlinesDrag/BMTodayHeadlinesDragCell.h
//
// BMTodayHeadlinesDragCell.h
// TodayHeadlinesDrag
//
// Created by __liangdahong on 2017/7/23.
// Copyright © 2017年 http://idhong.com. All rights reserved.
//
#import <UIKit/UIKit.h>
@class BMTodayHeadlinesDragModel;
@interface BMTodayHeadlinesDragCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *removeButton;
@end
|
asiosldh/BMDragCellCollectionView
|
BMDragCellCollectionViewDemo/BMDragCellCollectionViewDemo/Demo/AlipayVC/View/BMAlipayHeaderCollectionView.h
|
<gh_stars>100-1000
//
// BMAlipayHeaderCollectionView.h
// BMDragCellCollectionViewDemo
//
// Created by __liangdahong on 2017/7/25.
// Copyright © 2017年 http://idhong.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "XXNibBridge.h"
@interface BMAlipayHeaderCollectionView : UIView <XXNibBridge>
@end
|
H9660/bitstream
|
ieee/ethernet.h
|
<reponame>H9660/bitstream
/*****************************************************************************
* ethernet.h: Ethernet frames
*****************************************************************************
* Copyright (C) 2015 VideoLAN
*
* Authors: <NAME> <<EMAIL>>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*****************************************************************************/
/*
* Normative references:
* - IEEE Std 802.3-2012 (December 2012)
* - IETF RFC 7042 IANA Considerations and IETF Protocol
* and Documentation Usage for IEEE 802 Parameters (October 2013)
*/
#ifndef __BITSTREAM_IEEE_ETHERNET_H__
#define __BITSTREAM_IEEE_ETHERNET_H__
#include <stdbool.h>
#include <stdint.h>
#include <string.h> /* memcpy */
#ifdef __cplusplus
extern "C"
{
#endif
#define ETHERNET_ADDR_LEN 6
#define ETHERNET_HEADER_LEN (2*ETHERNET_ADDR_LEN + 2)
#define ETHERNET_VLAN_LEN 4
#define ETHERNET_TYPE_IP 0x0800
#define ETHERNET_TYPE_ARP 0x0806
#define ETHERNET_TYPE_RARP 0x8035
#define ETHERNET_TYPE_VLAN 0x8100
#define ETHERNET_TYPE_IPV6 0x86DD
#define ETHERNET_TYPE_PPP 0x880B
#define ETHERNET_TYPE_MPLS 0x8847
#define ETHERNET_TYPE_PPPOE_DISC 0x8863
#define ETHERNET_TYPE_PPPOE_SESSION 0x8864
#define ETHERNET_TYPE_LLDP 0x88CC
static inline uint8_t *ethernet_dstaddr(uint8_t *p_ethernet)
{
return p_ethernet;
}
static inline void ethernet_get_dstaddr(const uint8_t *p_ethernet, uint8_t *p_addr)
{
memcpy(p_addr, p_ethernet, ETHERNET_ADDR_LEN);
}
static inline void ethernet_set_dstaddr(uint8_t *p_ethernet, const uint8_t *p_addr)
{
memcpy(ethernet_dstaddr(p_ethernet), p_addr, ETHERNET_ADDR_LEN);
}
static inline uint8_t *ethernet_srcaddr(uint8_t *p_ethernet)
{
return p_ethernet + ETHERNET_ADDR_LEN;
}
static inline void ethernet_get_srcaddr(const uint8_t *p_ethernet, uint8_t *p_addr)
{
memcpy(p_addr, p_ethernet + ETHERNET_ADDR_LEN, ETHERNET_ADDR_LEN);
}
static inline void ethernet_set_srcaddr(uint8_t *p_ethernet, const uint8_t *p_addr)
{
memcpy(ethernet_srcaddr(p_ethernet), p_addr, ETHERNET_ADDR_LEN);
}
static inline uint16_t ethernet_get_lentype(const uint8_t *p_ethernet)
{
return (p_ethernet[12] << 8) | p_ethernet[13];
}
static inline void ethernet_set_lentype(uint8_t *p_ethernet, uint16_t lentype)
{
p_ethernet[12] = (lentype & 0xff00) >> 8;
p_ethernet[13] = (lentype & 0xff);
}
static inline uint8_t *ethernet_payload(uint8_t *p_ethernet)
{
if (ethernet_get_lentype(p_ethernet) != ETHERNET_TYPE_VLAN)
return p_ethernet + ETHERNET_HEADER_LEN;
else
return p_ethernet + ETHERNET_HEADER_LEN + ETHERNET_VLAN_LEN;
}
static inline uint8_t ethernet_vlan_get_priority(uint8_t *p_ethernet)
{
return (p_ethernet[ETHERNET_HEADER_LEN] & 0xe0) >> 5;
}
static inline void ethernet_vlan_set_priority(uint8_t *p_ethernet, uint8_t priority)
{
p_ethernet[ETHERNET_HEADER_LEN] &= ~0xe0;
p_ethernet[ETHERNET_HEADER_LEN] |= (priority & 0x7) << 5;
}
static inline bool ethernet_vlan_get_cfi(uint8_t *p_ethernet)
{
return (p_ethernet[ETHERNET_HEADER_LEN] & 0x10) == 0x10;
}
static inline void ethernet_vlan_set_cfi(uint8_t *p_ethernet, bool cfi)
{
p_ethernet[ETHERNET_HEADER_LEN] &= ~0x10;
p_ethernet[ETHERNET_HEADER_LEN] |= cfi << 4;
}
static inline uint16_t ethernet_vlan_get_id(uint8_t *p_ethernet)
{
return (p_ethernet[ETHERNET_HEADER_LEN+0] & 0xf) << 8
| p_ethernet[ETHERNET_HEADER_LEN+1];
}
static inline void ethernet_vlan_set_id(uint8_t *p_ethernet, uint16_t id)
{
p_ethernet[ETHERNET_HEADER_LEN+0] &= ~0xf;
p_ethernet[ETHERNET_HEADER_LEN+0] |= (id & 0xf00) >> 8;
p_ethernet[ETHERNET_HEADER_LEN+1] = (id & 0x0ff);
}
static inline uint16_t ethernet_vlan_get_lentype(uint8_t *p_ethernet)
{
return (p_ethernet[ETHERNET_HEADER_LEN+2] << 8)
| p_ethernet[ETHERNET_HEADER_LEN+3];
}
static inline void ethernet_vlan_set_lentype(uint8_t *p_ethernet, uint16_t lentype)
{
p_ethernet[ETHERNET_HEADER_LEN+2] = (lentype & 0xff00) >> 8;
p_ethernet[ETHERNET_HEADER_LEN+3] = (lentype & 0xff);
}
#ifdef __cplusplus
}
#endif
#endif
|
wu2meng3/DielectricKit
|
src/undef.h
|
<reponame>wu2meng3/DielectricKit<filename>src/undef.h
! use between inclusions of f_defs.h in template modules
! list here everything defined differently by flavor in f_defs.h
! these undefs prevent lots of warnings from cpp
#undef MYFLAVOR
#undef SCALAR
#undef MPI_SCALAR
#undef MYCONJG
#undef MYREAL
#undef X
#undef pX
#undef ZERO
#undef ONE
#undef SCALARIFY
#undef SCALARIFY2
#undef COMPLEXIFY
#undef SCALARSIZE
#undef ONLYIFCPLX
#undef MYABS2
!! Local Variables:
!! mode: f90
!! coding: utf-8
!! End:
|
wu2meng3/DielectricKit
|
src/compiler.h
|
! Created Sept 2011 by DAS.
! Define characteristics of various compilers, via compiler symbols (e.g. -DGNU)
! to be used directly from the arch.mk files, and then defining what we need to do
! for that compiler via the symbols for various properties (e.g. NOSIZEOF).
! Ideally, to support a new compiler, one need only change this file, adding a
! new block to define what -DNEWCOMPILER would mean.
! NOTE: of course, Makefile-level issues still need to be handled in common-rules.mk
#ifdef PGI
# define MCLOCKINT
# define CENTISEC
# define HOSTNAMEINT
# define FTELLINT
# define HAS_SLEEP
# define COMPILER_STR "PGI"
#endif
#ifdef INTEL
# define SIZEOF64
# define HOSTNAMENOE
# define HOSTNAMEMOD
# define MILLISEC
# define FTELLINT
# define HAS_SLEEP
# define COMPILER_STR "INTEL"
#endif
! very ancient version may require NOSIZEOF
#ifdef GNU
# define SIZEOF64
# define MICROSEC
# define NOIARGCINT
# define FTELLROUTINE
# define HAS_SLEEP
# define COMPILER_STR "GNU"
#endif
#ifdef G95
# define CPUTIME
# define NOFSEEK
# define NOOPENMP
# define HAS_SLEEP
# define COMPILER_STR "G95"
#endif
! open64 is very similar to path, it is an open-sourced version of it
! omp_lib.f90 needed to do OpenMP, see common-rules.mk.
#ifdef OPEN64
# define NOSIZEOF
# define CALLFLUSH
# define HOSTNAMEINT
# define NOFSEEK ! compiles, but does not seem to work
! # define FTELLROUTINE
# define NOOPENMP
# define HAS_SLEEP
# define COMPILER_STR "OPEN64"
#endif
! path before 4.0.9 lacks SIZEOF
#ifdef PATH
# define CALLFLUSH
# define HOSTNAMEINT
# define NOFSEEK ! compiles, but does not seem to work
! # define FTELLROUTINE
# define HAS_SLEEP
# define COMPILER_STR "PATH"
#endif
! both open64 and path die on fseek with:
!lib-5002 : UNRECOVERABLE library error
! This FFIO request is not supported.
!
!Encountered during a GETPOS on unit 8
#ifdef XLF
# define NOFLUSH
# define HOSTNAMEUNDERSCORE
# define MCLOCKINT
# define CENTISEC
# define HOSTNAMEINT
# define NOFSEEK ! compiles, but does not seem to work
! # define FTELLINT
# define COMPILER_STR "XLF"
#endif
#ifdef SUN
# define NOSIZEOF
# define CPUTIME
# define HOSTNAMEINT
# define NOFSEEK ! compiles, but does not seem to work
! # define FTELLINT
# define HAS_SLEEP
# define COMPILER_STR "SUN"
#endif
#ifdef NAG
# define NOSIZEOF
# define CPUTIME
# define NOOPENMP
# define GETHOSTNAME
# define NOIARGCINT
# define NOFSEEK
# define SYSTEMMOD_NAG
! sleep is defined in f90_unix_env
# define HAS_SLEEP
# define COMPILER_STR "NAG"
#endif
#ifdef ABSOFT
# define CALLFLUSH
# define CPUTIME
# define NOIARGCINT
# define SYSTEMFUNCTION
# define FSEEKFUNCTION
# define SYSTEMMOD_AB
! sleep is defined in unix_library
# define NOFSEEK ! compiles, but does not seem to work
! # define FTELLINT sleep is defined in unix_library
# define HAS_SLEEP
# define COMPILER_STR "ABSOFT"
#endif
! cce 7.4.4 and before support sizeof for intrinsic types, but need NOSIZEOF_TYPE
! cce 8.0.0 and later do not allow sizeof for multidimensional arrays, requiring us
! to turn sizeof off everywhere. Why would Cray do this?
#ifdef CRAY
# define HOSTNAMEINT
# define NOFSEEK
# define CPUTIME
# define NOSIZEOF
# define HAS_SLEEP
# define COMPILER_STR "CRAY"
#endif
#ifndef COMPILER_STR
# define COMPILER_STR "UNKNOWN"
#endif
! It is considered a bug in OPEN64 that sizeof will not work in our code.
#if defined NOSIZEOF
# define SIZEOF(x) 1
#elif defined SIZEOFTRICK
# define SIZEOF(x) int(size(x),8)*int(sizeof(reshape(x,(/ 1 /))),8)
#else
# define SIZEOF(x) sizeof(x)
#endif
#if defined CALLFLUSH
! XLF will not accept this version
# define FLUSH(x) call flush(x)
#elif defined NOFLUSH
# define FLUSH(x)
#else
! Fortran 2003 prefers this as a statement, not an intrinsic
# define FLUSH(x) flush(x)
#endif
! on some platforms there is a different return value for sizeof if build is 64-bit
#if defined SIZEOF64 && defined _LP64
# define INTSIZEOF integer*8
#elif defined SIZEOFTRICK
# define INTSIZEOF integer*8
#else
# define INTSIZEOF integer
#endif
! name of routine to get name of host program is running on
#if defined HOSTNAMEUNDERSCORE
# define HOSTNAME hostnm_
#elif defined HOSTNAMENOE
# define HOSTNAME hostnam
#else
# define HOSTNAME hostnm
#endif
#ifdef GETHOSTNAME
# define HOSTNAMECALL(name, stat) call gethostname(name)
#else
# define HOSTNAMECALL(name, stat) stat = HOSTNAME(name)
#endif
! module required for HOSTNAME routine to be usable
#if defined HOSTNAMEMOD
# define USEHOSTNAMEMOD use ifport, only : hostnam
#else
# define USEHOSTNAMEMOD
#endif
! note: interfaces are split into two lines because ifort for some reason decrees of
! 'end interface' : "END statement must be only statement on line".
! HOSTNAMEINT enables interface for HOSTNAME routine in intrinsics_m
#if defined HOSTNAMEINT
# define HOSTNAME_INTERFACE \
interface; \
integer function HOSTNAME(name); \
character(len=*), intent(out) :: name; \
end function HOSTNAME
# define HOSTNAME_INTERFACE2 end interface
#else
# define HOSTNAME_INTERFACE
# define HOSTNAME_INTERFACE2
#endif
! how to get the cpu time in seconds
#if defined CPUTIME
# define TIMGET(cpu) call cpu_time(cpu)
#elif defined MICROSEC
# define TIMGET(cpu) cpu=mclock()*1.0d-6
#elif defined MILLISEC
# define TIMGET(cpu) cpu=mclock()*1.0d-3
#elif defined CENTISEC
# define TIMGET(cpu) cpu=mclock()*1.0d-2
#else
# define TIMGET(cpu) cpu=0.0d0
#endif
! interface required for mclock routine (timing) to be usable
#if defined MCLOCKINT
# define MCLOCK_INTERFACE interface; integer function mclock(); end function mclock
# define MCLOCK_INTERFACE2 end interface
#else
# define MCLOCK_INTERFACE
# define MCLOCK_INTERFACE2
#endif
! interface required for iargc routine (command-line arguments) to be usable
#ifdef NOIARGCINT
# define IARGC_INTERFACE
# define IARGC_INTERFACE2
#else
# define IARGC_INTERFACE interface; integer function iargc(); end function iargc
# define IARGC_INTERFACE2 end interface
#endif
! ftell gives you the current location in a file, to fseek back to it
#ifdef FTELLINT
# define FTELL_INTERFACE \
interface; \
integer function ftell(unit); \
integer, intent(in) :: unit; \
end function ftell
# define FTELL_INTERFACE2 end interface
#else
# define FTELL_INTERFACE
# define FTELL_INTERFACE2
#endif
! if no fseek, ftell is useless
#ifdef FTELLROUTINE
# define FTELLCALL(unit, loc) call ftell(unit, loc)
#elif defined NOFSEEK
# define FTELLCALL(unit, loc)
#else
# define FTELLCALL(unit, loc) loc = ftell(unit)
#endif
! #warning This compiler does not support fseek.
! fseek returns to a location in a file, bookmarked by ftell. G95 lacks it
#ifdef NOFSEEK
# define FSEEKCALL(unit, loc, whence) call die("This compiler does not support fseek.")
#elif defined FSEEKFUNCTION
# define FSEEKCALL(unit, loc, whence) alc = fseek(unit, loc, whence)
#else
# define FSEEKCALL(unit, loc, whence) call fseek(unit, loc, whence)
#endif
! intrinsic module for OpenMP. external for Open64 (see common-rules.mk). NAG and G95 do not support OpenMP
#ifdef NOOPENMP
# define USEOMPLIB
#else
# define USEOMPLIB use omp_lib
#endif
! using a global var here to avoid need for conditional local declaration
#ifdef NOSYSTEM
# define SYSTEMCALL(command) write(0,*) 'WARNING: system call not available.'
#elif defined SYSTEMFUNCTION
# define SYSTEMCALL(command) alc = system(command)
#else
# define SYSTEMCALL(command) call system(command)
#endif
#ifdef SYSTEMMOD_AB
# define SYSTEMMOD use unix_library
#elif defined SYSTEMMOD_NAG
# define SYSTEMMOD use f90_unix_env; use f90_unix_proc
#else
# define SYSTEMMOD
#endif
#ifdef HAS_SLEEP
# define MYSLEEP(x) call sleep(x)
#else
# define MYSLEEP(x)
#endif
!! Local Variables:
!! mode: f90
!! coding: utf-8
!! End:
|
wu2meng3/DielectricKit
|
src/spglib-1.0.9/spglib.h
|
/* spglib.h version 1.0.9 */
/* Copyright (C) 2008 <NAME> */
#ifndef __spglib_H__
#define __spglib_H__
/* SPGCONST is used instead of 'const' so to avoid gcc warning. */
/* However there should be better way than this way.... */
#define SPGCONST
/*
------------------------------------------------------------------
lattice: Lattice vectors (in Cartesian)
[ [ a_x, b_x, c_x ],
[ a_y, b_y, c_y ],
[ a_z, b_z, c_z ] ]
position: Atomic positions (in fractional coordinates)
[ [ x1_a, x1_b, x1_c ],
[ x2_a, x2_b, x2_c ],
[ x3_a, x3_b, x3_c ],
... ]
types: Atom types, i.e., species identified by number
[ type_1, type_2, type_3, ... ]
rotation: Rotation matricies of symmetry operations
each rotation is:
[ [ r_aa, r_ab, r_ac ],
[ r_ba, r_bb, r_bc ],
[ r_ca, r_cb, r_cc ] ]
translation: Translation vectors of symmetry operations
each translation is:
[ t_a, t_b, t_c ]
symprec: Tolerance of atomic positions (in fractional coordinate)
in finding symmetry operations
------------------------------------------------------------------
Definitio of the operation:
r : rotation 3x3 matrix
t : translation vector
x_new = r * x + t:
[ x_new_a ] [ r_aa, r_ab, r_ac ] [ x_a ] [ t_a ]
[ x_new_b ] = [ r_ba, r_bb, r_bc ] * [ x_b ] + [ t_b ]
[ x_new_c ] [ r_ca, r_cb, r_cc ] [ x_c ] [ t_c ]
------------------------------------------------------------------
*/
typedef struct {
int spacegroup_number;
char international_symbol[11];
char hall_symbol[17];
double transformation_matrix[3][3]; /* bravais_lattice = T * original_lattice */
double origin_shift[3]; /* Origin shift in Bravais lattice */
int n_operations; /* Symmetry operations from database */
int (*rotations)[3][3];
double (*translations)[3];
int n_atoms;
int *wyckoffs; /* Wyckoff letters */
int *equivalent_atoms;
} SpglibDataset;
typedef struct {
int size;
int (*triplets)[3];
int *weights;
int mesh[3];
int (*mesh_points)[3];
} SpglibTriplets;
SpglibDataset * spg_get_dataset( SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
void spg_free_dataset( SpglibDataset *dataset );
/* Find symmetry operations. The operations are stored in */
/* ``rotatiion`` and ``translation``. The number of operations is */
/* return as the return value. Rotations and translations are */
/* given in fractional coordinates, and ``rotation[i]`` and */
/* ``translation[i]`` with same index give a symmetry oprations, */
/* i.e., these have to be used togather. */
int spg_get_symmetry( int rotation[][3][3],
double translation[][3],
const int max_size,
SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
/* Return exact number of symmetry operations. This function may */
/* be used in advance to allocate memoery space for symmetry */
/* operations. Only upper bound is required, */
/* ``spg_get_max_multiplicity`` can be used instead of this */
/* function and ``spg_get_max_multiplicity`` is faster than this */
/* function. */
int spg_get_multiplicity( SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
/* Considering periodicity of crystal, one of the possible smallest */
/* lattice is searched. The lattice is stored in ``smallest_lattice``. */
int spg_get_smallest_lattice( double smallest_lattice[3][3],
SPGCONST double lattice[3][3],
const double symprec );
/* Upper bound of number of symmetry operations is found. */
/* See ``spg_get_multiplicity``. */
int spg_get_max_multiplicity( SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
/* A primitive cell is found from an input cell. Be careful that */
/* ``lattice``, ``position``, and ``types`` are overwritten. */
/* ``num_atom`` is returned as return value. */
/* When any primitive cell is not found, 0 is returned. */
int spg_find_primitive( double lattice[3][3],
double position[][3],
int types[],
const int num_atom,
const double symprec );
/* Space group is found in international table symbol (``symbol``) and */
/* number (return value). 0 is returned when it fails. */
int spg_get_international( char symbol[11],
SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
/* Space group is found in schoenflies (``symbol``) and as number (return */
/* value). 0 is returned when it fails. */
int spg_get_schoenflies( char symbol[10],
SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
/* Bravais lattice with internal atomic points are returned. */
/* The arrays are require to have 4 times larger memory space */
/* those of input cell. */
/* When bravais lattice could not be found, or could not be */
/* symmetrized, 0 is returned. */
int spg_refine_cell( double lattice[3][3],
double position[][3],
int types[],
const int num_atom,
const double symprec );
/* Irreducible k-points are searched from the input k-points */
/* (``kpoints``). The result is returned as a map of */
/* numbers (``map``), where ``kpoints`` and ``map`` have to have */
/* the same number of elements. The array index of ``map`` */
/* corresponds to the reducible k-point numbering. After finding */
/* irreducible k-points, the indices of the irreducible k-points */
/* are mapped to the elements of ``map``, i.e., number of unique */
/* values in ``map`` is the number of the irreducible k-points. */
/* The number of the irreducible k-points is also returned as the */
/* return value. */
int spg_get_ir_kpoints( int map[],
SPGCONST double kpoints[][3],
const int num_kpoints,
SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const int is_time_reversal,
const double symprec );
/* Irreducible reciprocal grid points are searched from uniform */
/* mesh grid points specified by ``mesh`` and ``is_shift``. */
/* ``mesh`` stores three integers. Reciprocal primitive vectors */
/* are divided by the number stored in ``mesh`` with (0,0,0) point */
/* centering. The centering can be shifted only half of one mesh */
/* by setting 1 for each ``is_shift`` element. If 0 is set for */
/* ``is_shift``, it means there is no shift. This limitation of */
/* shifting enables the irreducible k-point search significantly */
/* faster when the mesh is very dense. */
/* The reducible uniform grid points are returned in reduced */
/* coordinates as ``grid_point``. A map between reducible and */
/* irreducible points are returned as ``map`` as in the indices of */
/* ``grid_point``. The number of the irreducible k-points are */
/* returned as the return value. The time reversal symmetry is */
/* imposed by setting ``is_time_reversal`` 1. */
int spg_get_ir_reciprocal_mesh( int grid_point[][3],
int map[],
const int mesh[3],
const int is_shift[3],
const int is_time_reversal,
SPGCONST double lattice[3][3],
SPGCONST double position[][3],
const int types[],
const int num_atom,
const double symprec );
/* The irreducible k-points are searched from unique k-point mesh */
/* grids from real space lattice vectors and rotation matrices of */
/* symmetry operations in real space with stabilizers. The */
/* stabilizers are written in reduced coordinates. Number of the */
/* stabilizers are given by ``num_q``. Reduced k-points are stored */
/* in ``map`` as indices of ``grid_point``. The number of the */
/* reduced k-points with stabilizers are returned as the return */
/* value. */
int spg_get_stabilized_reciprocal_mesh( int grid_point[][3],
int map[],
const int mesh[3],
const int is_shift[3],
const int is_time_reversal,
SPGCONST double lattice[3][3],
const int num_rot,
SPGCONST int rotations[][3][3],
const int num_q,
SPGCONST double qpoints[][3],
const double symprec );
/* Irreducible triplets of k-points are searched under conservation of */
/* :math:``\mathbf{k}_1 + \mathbf{k}_2 + \mathbf{k}_3 = \mathbf{G}``. */
/* Don't forget to free memory space of triplets using spg_free_triplets */
SpglibTriplets * spg_get_triplets_reciprocal_mesh( const int mesh[3],
const int is_time_reversal,
SPGCONST double lattice[3][3],
const int num_rot,
SPGCONST int rotations[][3][3],
const double symprec );
void spg_free_triplets( SpglibTriplets * triplets );
int spg_get_triplets_reciprocal_mesh_at_q( int weights[],
int grid_points[][3],
int third_q[],
const int grid_point,
const int mesh[3],
const int is_time_reversal,
SPGCONST double lattice[3][3],
const int num_rot,
SPGCONST int rotations[][3][3],
const double symprec );
int spg_extract_triplets_reciprocal_mesh_at_q( int triplets_at_q[][3],
int weight_triplets_at_q[],
const int fixed_grid_number,
const int num_triplets,
SPGCONST int triplets[][3],
const int weight_triplets[],
const int mesh[3],
const int is_time_reversal,
SPGCONST double lattice[3][3],
const int num_rot,
SPGCONST int rotations[][3][3],
const double symprec );
#endif
|
wu2meng3/DielectricKit
|
src/f_defs.h
|
<filename>src/f_defs.h
#define IMAG(x) AIMAG(x)
#define CONJG(x) CONJG(x)
#define CMPLX(x,y) CMPLX(x,y,kind=DPC)
#define ABS2(x) (DBLE(x)**2 + AIMAG(x)**2)
!The following macro puts any point/array in the [-0.5, 0.5) range:
#define MIN_RANGE(x) (x - FLOOR(x + 0.5d0))
!The following macro puts any point/array in the [0, 1) range:
#define UNIT_RANGE(x) (x - FLOOR(x))
!Integer division of a/b rounded up*/
#define DIVUP(a,b) ((a+b-1)/(b))
!Rounds a up to the smallest multiple of b*/
#define ROUNDUP(a,b) (DIVUP(a,b)*(b))
! disable Fortran OMP pragmas if not -DOMP*/
! note: C standard does not permit $ in identifiers, however this seems acceptable
! as an extension, for all versions of cpp I tried. --DAS
#ifndef OMP
#define $OMP disabled
#define $omp disabled
#endif
#define MPI_REAL_DP MPI_DOUBLE_PRECISION
#define MPI_COMPLEX_DPC MPI_DOUBLE_COMPLEX
#define RFLAVOR "Real"
#define CFLAVOR "Complex"
#ifdef CPLX
#define MYFLAVOR CFLAVOR
#define SCALAR COMPLEX(DPC)
#define MPI_SCALAR MPI_COMPLEX_DPC
#define MYCONJG(x) CONJG(x)
#define MYREAL(x) REAL(x,kind=DP)
#define MYABS2(x) ABS2(x)
#define X(x) z ## x
#define pX(x) pz ## x
#define ZERO (0.0d0,0.0d0)
#define ONE (1.0d0,0.0d0)
#define SCALARIFY(x) (x)
#define SCALARIFY2(x,y) DCMPLX(x,y)
!#define SCALARIFY2(x,y) CMPLX(x,y)
#define COMPLEXIFY(x) (x)
#define SCALARSIZE 2
#define ONLYIFCPLX(x) x,
#else
#define MYFLAVOR RFLAVOR
#define SCALAR REAL(DP)
#define MPI_SCALAR MPI_REAL_DP
#define MYCONJG(x) (x)
#define MYREAL(x) (x)
#define MYABS2(x) ((x)**2)
#define X(x) d ## x
#define pX(x) pd ## x
#define ZERO 0.0d0
#define ONE 1.0d0
!#define SCALARIFY(x) real(x,kind=DP)
#define SCALARIFY(x) DBLE(x,kind=DP)
!#define SCALARIFY2(x,y) real(x,kind=DP)
#define SCALARIFY2(x,y) DBLE(x,kind=DP)
!#define COMPLEXIFY(x) cmplx(x,kind=DPC)
#define COMPLEXIFY(x) DCMPLX(x,kind=DPC)
#define SCALARSIZE 1
#define ONLYIFCPLX(x)
#endif
! truncate spaces in string
!#!define TRUNC(s) trim(adjustl(s))
! Sun compiler has a length limit of 132 characters and won`t support these macros
#if defined(DEBUG) && (! defined(SUN) )
! Use this instead of the intrinsic 'allocate'
#define SAFE_ALLOCATE(x,y) \
allocate(x y,stat=alc); \
call alloc_check(alc,SIZEOF(x),#x,__FILE__,__LINE__,.true.)
! Do not use this directly
#define MY_DEALLOCATE(x) \
sz=SIZEOF(x);deallocate(x,stat=alc); \
call alloc_check(alc,sz,#x,__FILE__,__LINE__,.false.)
#else
! No checking for faster performance, if not in debug mode
#define SAFE_ALLOCATE(x,y) allocate(x y)
#define MY_DEALLOCATE(x) deallocate(x)
#endif
! Use this instead of the intrinsic 'deallocate' for pointers
#define SAFE_DEALLOCATE_P(x) \
if(associated(x))then;\
MY_DEALLOCATE(x);\
nullify(x);\
endif
! Use this instead of the intrinsic 'deallocate' for arrays
#define SAFE_DEALLOCATE(x) \
if(allocated(x))then;\
MY_DEALLOCATE(x);\
endif
!the TOSTRING macro converts a macro into a string
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#ifdef DEBUG
#define PUSH_SUB(routine) call push_sub(__FILE__+"."+TOSTRING(routine))
#define POP_SUB(routine) call pop_sub(__FILE__+"."+TOSTRING(routine))
#else
#define PUSH_SUB(routine)
#define POP_SUB(routine)
#endif
! ! deprecated identifiers
! #define DFLOAT @@_use_dble_instead_@@
! #define DREAL @@_use_dble_instead_@@
! #define REAL @@_use_dble_instead_@@
! !#define DIMAG @@_use_IMAG_instead_@@
! #define DCONJG @@_use_CONJG_instead_@@
! !#define DCMPLX @@_use_CMPLX_instead_@@
! #define dfloat @@_use_dble_instead_@@
! #define dreal @@_use_dble_instead_@@
! !#define dimag @@_use_IMAG_instead_@@
! #define dconjg @@_use_CONJG_instead_@@
! #define dcmplx @@_use_CMPLX_instead_@@
#include "compiler.h"
!! Local Variables:
!! mode: f90
!! coding: utf-8
!! End:
|
wu2meng3/DielectricKit
|
src/spglib-1.0.9/spglib_f_meta.c
|
/******************************************************************************
*
* spglib_f_meta Originally by FHJ Last Modified 11/08/2012 (FHJ)
*
*
* SHORT
* BerkeleyGW meta wrapper for spglib.
*
* LONG
* spglib`s Fortran wrappers assume the Fortran compiler will append an
* underscore after each symbol`s name, which is not true for all compilers,
* such as XL. This can lead to terrible results, specially since the symbols
* without underscores are also available in the library, but take different
* arguments. This file fixes this problem by exporting symbols with both
* "_f" and "_f_" appended to the names, so that they should work regardless
* of the name mangling.
*
* This file is part of the BerkeleyGW package.
*
******************************************************************************/
/* Original symbol from spglib_f.c */
extern void spg_get_multiplicity_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_multiplicity_f( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_multiplicity_(size,
lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_multiplicity_f_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_multiplicity_(size,
lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_get_max_multiplicity_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_max_multiplicity_f( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_max_multiplicity_(size,
lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_max_multiplicity_f_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_max_multiplicity_(size,
lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_get_symmetry_( int *nsym,
int rot[][3][3],
double trans[][3],
int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_symmetry_f( int *nsym,
int rot[][3][3],
double trans[][3],
int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_symmetry_(nsym,
rot,
trans,
size,
lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_symmetry_f_( int *nsym,
int rot[][3][3],
double trans[][3],
int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_symmetry_(nsym,
rot,
trans,
size,
lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_get_smallest_lattice_( double smallest_lattice[3][3],
double lattice[3][3],
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_smallest_lattice_f( double smallest_lattice[3][3],
double lattice[3][3],
double *symprec ) {
spg_get_smallest_lattice_(smallest_lattice,
lattice,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_smallest_lattice_f_( double smallest_lattice[3][3],
double lattice[3][3],
double *symprec ) {
spg_get_smallest_lattice_(smallest_lattice,
lattice,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_get_international_( int *spacegroup,
char symbol[11],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_international_f( int *spacegroup,
char symbol[11],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_international_(spacegroup,
symbol,
lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_international_f_( int *spacegroup,
char symbol[11],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_international_(spacegroup,
symbol,
lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_refine_cell_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_refine_cell_f( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_refine_cell_(lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_refine_cell_f_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_refine_cell_(lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_get_schoenflies_( int *spacegroup,
char symbol[10],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_schoenflies_f( int *spacegroup,
char symbol[10],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_schoenflies_(spacegroup,
symbol,
lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_schoenflies_f_( int *spacegroup,
char symbol[10],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_schoenflies_(spacegroup,
symbol,
lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_find_primitive_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_find_primitive_f( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_find_primitive_(lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_find_primitive_f_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_find_primitive_(lattice,
position,
types,
num_atom,
symprec );
}
/* Original symbol from spglib_f.c */
extern void spg_get_ir_reciprocal_mesh_( int *num_ir_grid,
int grid_point[][3],
int map[],
int mesh[3],
int is_shift[3],
int *is_time_reversal,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
/* Wrapped symbol without underscore */
void spg_get_ir_reciprocal_mesh_f( int *num_ir_grid,
int grid_point[][3],
int map[],
int mesh[3],
int is_shift[3],
int *is_time_reversal,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_ir_reciprocal_mesh_(num_ir_grid,
grid_point,
map,
mesh,
is_shift,
is_time_reversal,
lattice,
position,
types,
num_atom,
symprec );
}
/* Wrapped symbol with underscore */
void spg_get_ir_reciprocal_mesh_f_( int *num_ir_grid,
int grid_point[][3],
int map[],
int mesh[3],
int is_shift[3],
int *is_time_reversal,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec ) {
spg_get_ir_reciprocal_mesh_(num_ir_grid,
grid_point,
map,
mesh,
is_shift,
is_time_reversal,
lattice,
position,
types,
num_atom,
symprec );
}
|
wu2meng3/DielectricKit
|
src/spglib-1.0.9/spglib_f.c
|
/* NOTE: This file is not actually part of spglib 1.0.9 although it appears
to have been forgotten by accident since it is mentioned in the documentation.
I obtained it by e-mailing the author of spglib. --DAS Dec 2011 */
#include "spglib.h"
#include <string.h>
void spg_get_multiplicity_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_get_max_multiplicity_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_get_symmetry_( int *nsym,
int rot[][3][3],
double trans[][3],
int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_get_smallest_lattice_( double smallest_lattice[3][3],
double lattice[3][3],
double *symprec );
void spg_get_international_( int *spacegroup,
char symbol[11],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_refine_cell_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_get_schoenflies_( int *spacegroup,
char symbol[10],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_find_primitive_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_get_ir_reciprocal_mesh_( int *num_ir_grid,
int grid_point[][3],
int map[],
int mesh[3],
int is_shift[3],
int *is_time_reversal,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec );
void spg_get_multiplicity_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
*size = spg_get_multiplicity(lattice, position, types, *num_atom, *symprec);
}
void spg_get_max_multiplicity_( int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec)
{
*size = spg_get_max_multiplicity(lattice, position, types, *num_atom, *symprec);
}
void spg_get_symmetry_( int *nsym,
int rot[][3][3],
double trans[][3],
int *size,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
*nsym = spg_get_symmetry(rot, trans, *size, lattice, position,
types, *num_atom, *symprec);
}
void spg_get_smallest_lattice_( double smallest_lattice[3][3],
double lattice[3][3],
double *symprec )
{
spg_get_smallest_lattice(smallest_lattice, lattice, *symprec);
}
void spg_get_international_( int *spacegroup,
char symbol[21],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
char symbol_c[21];
int i, length;
*spacegroup = spg_get_international(symbol_c, lattice, position, types,
*num_atom, *symprec);
length = strlen(symbol_c);
strncpy(symbol, symbol_c, length);
for (i=length; i<21; i++)
symbol[i] = ' ';
}
void spg_refine_cell_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
int num_atom_bravais;
num_atom_bravais = spg_refine_cell( lattice,
position,
types,
*num_atom,
*symprec);
*num_atom = num_atom_bravais;
}
void spg_get_schoenflies_( int *spacegroup,
char symbol[10],
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
char symbol_c[10];
int i, length;
*spacegroup = spg_get_schoenflies(symbol_c, lattice, position, types,
*num_atom, *symprec);
length = strlen(symbol_c);
strncpy(symbol, symbol_c, length);
for (i=length; i<10; i++)
symbol[i] = ' ';
}
void spg_find_primitive_( double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
*num_atom = spg_find_primitive(lattice, position, types, *num_atom,
*symprec);
}
void spg_get_ir_reciprocal_mesh_( int *num_ir_grid,
int grid_point[][3],
int map[],
int mesh[3],
int is_shift[3],
int *is_time_reversal,
double lattice[3][3],
double position[][3],
int types[],
int *num_atom,
double *symprec )
{
int i;
*num_ir_grid = spg_get_ir_reciprocal_mesh( grid_point,
map,
mesh,
is_shift,
*is_time_reversal,
lattice,
position,
types,
*num_atom,
*symprec );
for ( i = 0; i < mesh[0]*mesh[1]*mesh[2]; i++ ) {
map[i]++;
}
}
|
jonrood/simulations
|
smoke/fluid.h
|
<filename>smoke/fluid.h
#ifndef __FLUID_H
#define __FLUID_H
#include <stdio.h>
#define N 30 // must be N^2-2
#define SIZE ((N+2)*(N+2)*(N+2))
#define _I(x,y,z) (((z)<<10)+((y)<<5)+x)
#define SWAPFPTR(x,y) {float *t=x;x=y;y=t;}
class Fluid
{
protected:
float buffers[10][SIZE];
public:
float *d, *d0; // density
float *u, *u0; // velocity in x direction
float *v, *v0; // velocity in y direction
float *w, *w0; // velocity in z direction
protected:
// simulation methods
// beware: i changed stam's implementation from a destiation, source ordering
// of the parameters to source, destiation
void add_source(float* src, float *dst, float dt);
void add_buoyancy(float dt);
void set_bnd(int b, float* x);
void diffuse(int b, float* x0, float* x, float diff, float dt);
void advect(int b, float* x0, float* x, float* uu, float* vv, float* ww, float dt);
void project(void);
void vorticity_confinement(float dt);
void vel_step(float dt);
void dens_step(float dt);
void dens_temp_step(float dt);
// utility methods
void clear_buffer(float* x);
void clear_sources(void);
public:
float sd[SIZE], su[SIZE], sv[SIZE], sw[SIZE], sT[SIZE]; // sources for density and velocities
float diffusion, viscosity, buoyancy, vc_eps;
Fluid(void);
~Fluid(void);
void step(float dt);
void store(FILE *fp);
};
#endif
|
jonrood/simulations
|
fire/spectrum.h
|
#ifndef __SPECTRUM_H
#define __SPECTRUM_H
void spectrum(double t1, double t2, int n, unsigned char* d);
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.