diff options
author | Evan Lojewski <github@meklort.com> | 2019-05-05 19:17:10 -0600 |
---|---|---|
committer | Evan Lojewski <github@meklort.com> | 2019-05-05 19:17:10 -0600 |
commit | 7e5196c770e6a229e00c849de4fe41b6d962a7ef (patch) | |
tree | 62fa11179088876a4db411cbe09c4ba52dd6f38c | |
parent | 72eaf56f7ffaeb2d57cfdf63f32963bd08bfb290 (diff) | |
download | bcm5719-ortega-7e5196c770e6a229e00c849de4fe41b6d962a7ef.tar.gz bcm5719-ortega-7e5196c770e6a229e00c849de4fe41b6d962a7ef.zip |
More cleanup - headers.
-rw-r--r-- | ape/ape.h | 1 | ||||
-rw-r--r-- | include/types.h | 11 | ||||
-rw-r--r-- | libs/MII/include/MII.h | 2 | ||||
-rw-r--r-- | libs/NCSI/tests/tests.cpp | 47 | ||||
-rw-r--r-- | libs/NVRam/include/NVRam.h | 4 | ||||
-rw-r--r-- | libs/Network/include/Network.h | 21 | ||||
-rw-r--r-- | simulator/include/CXXRegister.h | 105 | ||||
-rw-r--r-- | stage1/stage1.h | 3 | ||||
-rw-r--r-- | utils/bcmregtool/apeloader/ape.h | 66 | ||||
-rw-r--r-- | utils/bcmregtool/apeloader/main.c | 2 |
10 files changed, 94 insertions, 168 deletions
@@ -47,5 +47,4 @@ void initRMU(void); - #endif /* APE_H */ diff --git a/include/types.h b/include/types.h index 64efd34..0b3baba 100644 --- a/include/types.h +++ b/include/types.h @@ -1,12 +1,11 @@ #ifndef TYPES_H #define TYPES_H +#define SECTION(__section__) __attribute__((section, __section__)) -#define SECTION(__section__) __attribute__((section, __section__)) +#define ARRAY_ELEMENTS(__array__) (sizeof(__array__) / sizeof(__array__[0])) -#define ARRAY_ELEMENTS(__array__) (sizeof(__array__)/sizeof(__array__[0])) - -#define DIVIDE_RND_UP(__value__, __round__) (((__value__) + (__round__) - 1) / (__round__)) +#define DIVIDE_RND_UP(__value__, __round__) (((__value__) + (__round__)-1) / (__round__)) #define DIVIDE_RND_DOWN(__value__, __round__) ((__value__) / (__round__)) typedef union { @@ -15,12 +14,12 @@ typedef union { struct { uint8_t pad[2]; - uint8_t u8[6]; + uint8_t u8[6]; } oct; struct { - uint32_t u32[2]; + uint32_t u32[2]; } word; } mac_t; diff --git a/libs/MII/include/MII.h b/libs/MII/include/MII.h index bfca1e2..85e9f9d 100644 --- a/libs/MII/include/MII.h +++ b/libs/MII/include/MII.h @@ -44,8 +44,8 @@ #ifndef MII_H #define MII_H -#include <stdint.h> #include <bcm5719_MII.h> +#include <stdint.h> #ifdef CXX_SIMULATOR typedef uint64_t mii_reg_t; diff --git a/libs/NCSI/tests/tests.cpp b/libs/NCSI/tests/tests.cpp index c74a1fd..efcc35a 100644 --- a/libs/NCSI/tests/tests.cpp +++ b/libs/NCSI/tests/tests.cpp @@ -3,14 +3,12 @@ #include <APE_APE_PERI.h> #include <Ethernet.h> #include <NCSI.h> - - #include <endian.h> uint32_t *gPacket; uint32_t gPacketLen; -uint32_t gTXPacket[0x300/4]; +uint32_t gTXPacket[0x300 / 4]; uint32_t gTXPacketPos; extern uint8_t select_package1[]; @@ -47,15 +45,14 @@ extern uint32_t disable_network_tx_len; extern uint32_t disable_channel_len; extern uint32_t deselect_package_len; - static uint32_t read_packet(uint32_t val, uint32_t offset, void *args) { uint32_t data = 0; - if(gPacketLen > 0) + if (gPacketLen > 0) { data = *gPacket; gPacket++; - if(gPacketLen > 4) + if (gPacketLen > 4) { gPacketLen -= 4; } @@ -63,7 +60,7 @@ static uint32_t read_packet(uint32_t val, uint32_t offset, void *args) { gPacketLen = 0; } - } + } return htobe32(data); } @@ -89,17 +86,15 @@ static uint32_t read_tx_status(uint32_t val, uint32_t offset, void *args) { RegAPE_PERIBmcToNcTxStatus_t stat; stat.r32 = 0; - stat.bits.InFifo = sizeof(gTXPacket) - (gTXPacketPos*4); + stat.bits.InFifo = sizeof(gTXPacket) - (gTXPacketPos * 4); return stat.r32; } - - -void send_packet(uint8_t* packet, uint32_t len) +void send_packet(uint8_t *packet, uint32_t len) { gTXPacketPos = 0; // reset response position. - gPacket = (uint32_t*)packet; + gPacket = (uint32_t *)packet; gPacketLen = len; uint32_t buffer[1024]; @@ -108,11 +103,11 @@ void send_packet(uint8_t* packet, uint32_t len) stat.r32 = APE_PERI.BmcToNcRxStatus.r32; // stat.print(); - if(stat.bits.New) + if (stat.bits.New) { int32_t bytes = stat.bits.PacketLength; int i = 0; - while(bytes > 0) + while (bytes > 0) { uint32_t word = (APE_PERI.BmcToNcReadBuffer.r32); buffer[i] = word; @@ -121,15 +116,16 @@ void send_packet(uint8_t* packet, uint32_t len) bytes -= 4; } - NetworkFrame_t *frame = ((NetworkFrame_t*)buffer); + NetworkFrame_t *frame = ((NetworkFrame_t *)buffer); - if(stat.bits.Bad) + if (stat.bits.Bad) { // TODO: ACK bad packet. APE_PERI.BmcToNcRxControl.bits.ResetBad = 1; - while(APE_PERI.BmcToNcRxControl.bits.ResetBad); + while (APE_PERI.BmcToNcRxControl.bits.ResetBad) + ; } - else if(!stat.bits.Passthru) + else if (!stat.bits.Passthru) { handleNCSIFrame(frame); @@ -137,8 +133,9 @@ void send_packet(uint8_t* packet, uint32_t len) EXPECT_EQ(gTXPacket[1], 0xffffffff); // Source/Dest MAC EXPECT_EQ(gTXPacket[2], 0xffffffff); // Dest MAC EXPECT_EQ(gTXPacket[3], 0x88f80001); // NCSI Type, Revision 1. - EXPECT_EQ(gTXPacket[4], buffer[4] | 0x8000); // IID, Channel, Package, Command | 0x80 - + EXPECT_EQ(gTXPacket[4], + buffer[4] | + 0x8000); // IID, Channel, Package, Command | 0x80 } else { @@ -147,10 +144,11 @@ void send_packet(uint8_t* packet, uint32_t len) } } +namespace +{ -namespace { - -TEST(Packet, SelectPackage) { +TEST(Packet, SelectPackage) +{ APE_PERI.BmcToNcRxStatus.r32.installReadCallback(read_rx_status, NULL); APE_PERI.BmcToNcReadBuffer.r32.installReadCallback(read_packet, NULL); APE_PERI.BmcToNcTxStatus.r32.installReadCallback(read_tx_status, NULL); @@ -158,8 +156,7 @@ TEST(Packet, SelectPackage) { APE_PERI.BmcToNcTxBuffer.r32.installWriteCallback(write_packet, NULL); APE_PERI.BmcToNcTxBufferLast.r32.installWriteCallback(write_packet, NULL); - send_packet(select_package1, select_package1_len); } -} // namespace +} // namespace diff --git a/libs/NVRam/include/NVRam.h b/libs/NVRam/include/NVRam.h index 405f6e9..3626ec5 100644 --- a/libs/NVRam/include/NVRam.h +++ b/libs/NVRam/include/NVRam.h @@ -63,7 +63,7 @@ void NVRam_disable(void); void NVRam_disableWrites(void); uint32_t NVRam_crc(const uint8_t *pcDatabuf, // Pointer to data buffer - uint32_t ulDatalen, // Length of data buffer in bytes - uint32_t crc); // Initial value + uint32_t ulDatalen, // Length of data buffer in bytes + uint32_t crc); // Initial value #endif /* NVRAM_H */ diff --git a/libs/Network/include/Network.h b/libs/Network/include/Network.h index 645569b..06bd57f 100644 --- a/libs/Network/include/Network.h +++ b/libs/Network/include/Network.h @@ -45,30 +45,27 @@ #ifndef NETWORK_H #define NETWORK_H -#include <stdint.h> -#include <stdbool.h> #include <APE_APE_PERI.h> +#include <stdbool.h> +#include <stdint.h> void Network_InitTxRx(void); uint32_t Network_TX_numBlocksNeeded(uint32_t frame_size); int32_t Network_TX_allocateBlock(void); -void Network_TX_transmitBePacket(uint8_t* packet, uint32_t length); -void Network_TX_transmitLePacket(uint8_t* packet, uint32_t length); +void Network_TX_transmitBePacket(uint8_t *packet, uint32_t length); +void Network_TX_transmitLePacket(uint8_t *packet, uint32_t length); void Network_TX_transmitPassthroughPacket(uint32_t length); -// void Network_TX_transmitPassthroughPacket(RegAPE_PERIBmcToNcRxStatus_t rx_status); +// void Network_TX_transmitPassthroughPacket(RegAPE_PERIBmcToNcRxStatus_t +// rx_status); -bool Network_RxLePatcket(uint32_t* buffer, uint32_t* length); +bool Network_RxLePatcket(uint32_t *buffer, uint32_t *length); bool Network_PassthroughRxPatcket(void); - - -void Network_SetMACAddr(uint16_t high, uint32_t low, uint32_t index, bool enabled); - - - +void Network_SetMACAddr(uint16_t high, uint32_t low, uint32_t index, + bool enabled); #endif /* NETWORK_H */
\ No newline at end of file diff --git a/simulator/include/CXXRegister.h b/simulator/include/CXXRegister.h index 3e40e3e..251a9b9 100644 --- a/simulator/include/CXXRegister.h +++ b/simulator/include/CXXRegister.h @@ -2,7 +2,7 @@ /// /// @file CXXRegister.h /// -/// @project +/// @project /// /// @brief C++ REgister wrapper code /// @@ -44,11 +44,11 @@ #ifndef CXX_REGISTER_H #define CXX_REGISTER_H -#include <vector> -#include <utility> -#include <stdio.h> +#include <iomanip> // std::setw #include <iostream> -#include <iomanip> // std::setw +#include <stdio.h> +#include <utility> +#include <vector> class CXXRegisterBase { @@ -60,27 +60,26 @@ public: mBaseRegister = NULL; mBitWidth = width; mBitPosition = offset; - for(unsigned int i = offset; i < offset + width; i++) + for (unsigned int i = offset; i < offset + width; i++) { mMask |= 1u << i; } } - virtual void setBaseRegister(CXXRegisterBase* base) + virtual void setBaseRegister(CXXRegisterBase *base) { // assert(base != NULL, "Base must not be null"); mBaseRegister = base; base->addRelatedRegister(this); - } - void setName(const char* name) + void setName(const char *name) { mName = name; } - const char* getName(void) + const char *getName(void) { return mName; } @@ -98,40 +97,42 @@ public: void print(unsigned int value, int indent = false) { unsigned int masked = value & mMask; - if(indent) + if (indent) { - std::cout << std::right << std::setw(35) << mName << ": 0x" << std::hex << (masked >> mBitPosition) << std::endl; + std::cout << std::right << std::setw(35) << mName << ": 0x" + << std::hex << (masked >> mBitPosition) << std::endl; } else { - std::cout << std::endl << std::left << std::setw(36) << mName << " 0x" << std::hex << (masked >> mBitPosition) << std::endl; + std::cout << std::endl + << std::left << std::setw(36) << mName << " 0x" + << std::hex << (masked >> mBitPosition) << std::endl; } } void printAll(unsigned int value) { - std::vector<CXXRegisterBase*>::iterator it; - for(it = mRelatedRegisters.begin(); it != mRelatedRegisters.end(); it++) + std::vector<CXXRegisterBase *>::iterator it; + for (it = mRelatedRegisters.begin(); it != mRelatedRegisters.end(); + it++) { (*it)->print(value, true); } } - protected: unsigned int mComponentOffset; unsigned int mBitPosition; unsigned int mBitWidth; unsigned int mMask; - const char* mName; + const char *mName; - std::vector<CXXRegisterBase*> mRelatedRegisters; + std::vector<CXXRegisterBase *> mRelatedRegisters; // This is the main controller register - CXXRegisterBase* mBaseRegister; - + CXXRegisterBase *mBaseRegister; - virtual void addRelatedRegister(CXXRegisterBase* related) + virtual void addRelatedRegister(CXXRegisterBase *related) { mRelatedRegisters.push_back(related); } @@ -145,10 +146,9 @@ protected: virtual void setRawValue(unsigned int) = 0; virtual void setTempValue(unsigned int) = 0; - - void doRelatedWritesBase(CXXRegisterBase* source) + void doRelatedWritesBase(CXXRegisterBase *source) { - if(source->mMask != this->mMask) + if (source->mMask != this->mMask) { // read latest value as we are only modifying some bits. doReadCallbacks(); @@ -159,11 +159,12 @@ protected: unsigned int base = getRawValue(); base &= ~(source->mMask); unsigned int tempValue = base | source->getRawValue(); - // printf("Updating base from %x & %x to %x (new write: %x)\n", getRawValue(), ~source->mMask, tempValue, source->getRawValue()); + // printf("Updating base from %x & %x to %x (new write: %x)\n", + // getRawValue(), ~source->mMask, tempValue, source->getRawValue()); setTempValue(tempValue); // Call the write callbacks. This may update the raw value as needed. - if(this != source) + if (this != source) { doWriteCallbacks(); } @@ -173,9 +174,9 @@ protected: { // printf("doRelatedWrites on %p\n", this); // Call doRelatedWrites on the base register. - if(mBaseRegister) + if (mBaseRegister) { - mBaseRegister->doRelatedWritesBase(this); + mBaseRegister->doRelatedWritesBase(this); } else { @@ -184,15 +185,16 @@ protected: } } - void doRelatedReadsBase(CXXRegisterBase* source) + void doRelatedReadsBase(CXXRegisterBase *source) { // Read the latest from the base register. doReadCallbacks(); unsigned int readValue = getTempValue(); // Update chained registers. - std::vector<CXXRegisterBase*>::iterator it; - for(it = mRelatedRegisters.begin(); it != mRelatedRegisters.end(); it++) + std::vector<CXXRegisterBase *>::iterator it; + for (it = mRelatedRegisters.begin(); it != mRelatedRegisters.end(); + it++) { // Update chained registers with latest data from base register. (*it)->setRawValue(readValue); @@ -208,7 +210,7 @@ protected: void doRelatedReads() { // Call doRelatedReads on the base register. - if(mBaseRegister) + if (mBaseRegister) { mBaseRegister->doRelatedReadsBase(this); } @@ -220,12 +222,13 @@ protected: } }; -template<typename T, unsigned int OFFSET, unsigned int WIDTH> class CXXRegister : public CXXRegisterBase +template<typename T, unsigned int OFFSET, unsigned int WIDTH> +class CXXRegister : public CXXRegisterBase { private: - typedef T (*callback_t)(T val, unsigned int, void*); - std::vector< std::pair<callback_t, void*> > mReadCallback; - std::vector< std::pair<callback_t, void*> > mWriteCallback; + typedef T (*callback_t)(T val, unsigned int, void *); + std::vector<std::pair<callback_t, void *>> mReadCallback; + std::vector<std::pair<callback_t, void *>> mWriteCallback; T mValue; T mTempValue; @@ -234,29 +237,29 @@ private: { T val = mTempValue; // call callbacks - typename std::vector<std::pair<callback_t, void*>>::iterator it; - for(it = mWriteCallback.begin(); it != mWriteCallback.end(); it++) + typename std::vector<std::pair<callback_t, void *>>::iterator it; + for (it = mWriteCallback.begin(); it != mWriteCallback.end(); it++) { callback_t callback; callback = (*it).first; - if(callback) + if (callback) { val = callback(val, mComponentOffset, (*it).second); } } - mValue = val; + mValue = val; } virtual void doReadCallbacks(void) { // call callbacks T val = mValue; - typename std::vector<std::pair<callback_t, void*>>::iterator it; - for(it = mReadCallback.begin(); it != mReadCallback.end(); it++) + typename std::vector<std::pair<callback_t, void *>>::iterator it; + for (it = mReadCallback.begin(); it != mReadCallback.end(); it++) { callback_t callback; callback = (*it).first; - if(callback) + if (callback) { val = callback(val, mComponentOffset, (*it).second); } @@ -301,7 +304,8 @@ private: virtual void setTempValue(unsigned int newVal) { - // printf("Setting temp: 0x%x (%x)\n", (newVal & mMask) >> mBitPosition, newVal); + // printf("Setting temp: 0x%x (%x)\n", (newVal & mMask) >> mBitPosition, + // newVal); mTempValue = (newVal & mMask) >> mBitPosition; } @@ -317,19 +321,18 @@ public: mValue = val; } - void installReadCallback(callback_t callback, void* args) + void installReadCallback(callback_t callback, void *args) { - mReadCallback.push_back( std::make_pair(callback, args) ); + mReadCallback.push_back(std::make_pair(callback, args)); } - void installWriteCallback(callback_t callback, void* args) + void installWriteCallback(callback_t callback, void *args) { - mWriteCallback.push_back( std::make_pair(callback, args) ); + mWriteCallback.push_back(std::make_pair(callback, args)); } virtual ~CXXRegister() { - } void print(void) @@ -356,7 +359,7 @@ public: return mValue; } - T operator=(CXXRegister<T,OFFSET,WIDTH> val) + T operator=(CXXRegister<T, OFFSET, WIDTH> val) { // Write doWrite((T)val); @@ -434,8 +437,8 @@ public: // Read - xor - Write return this->operator=(operator T() ^ val); } + protected: }; - #endif /* CXX_REGISTER_H */
\ No newline at end of file diff --git a/stage1/stage1.h b/stage1/stage1.h index b73eb47..dac77aa 100644 --- a/stage1/stage1.h +++ b/stage1/stage1.h @@ -45,8 +45,8 @@ #ifndef STAGE1_H #define STAGE1_H -#include <bcm5719_eeprom.h> #include <bcm5719_GEN.h> +#include <bcm5719_eeprom.h> void early_init_hw(void); void load_nvm_config(NVRAMContents_t *nvram); @@ -62,5 +62,4 @@ static inline void reportStatus(uint32_t code, uint8_t step) GEN.GenDataSig.r32 = (code | step); } - #endif /* STAGE1_H */ diff --git a/utils/bcmregtool/apeloader/ape.h b/utils/bcmregtool/apeloader/ape.h deleted file mode 100644 index d4c9ae6..0000000 --- a/utils/bcmregtool/apeloader/ape.h +++ /dev/null @@ -1,66 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// -/// @file stage1.h -/// -/// @project -/// -/// @brief Functions provided by stage1. -/// -//////////////////////////////////////////////////////////////////////////////// -/// -//////////////////////////////////////////////////////////////////////////////// -/// -/// @copyright Copyright (c) 2018, Evan Lojewski -/// @cond -/// -/// All rights reserved. -/// -/// Redistribution and use in source and binary forms, with or without -/// modification, are permitted provided that the following conditions are met: -/// 1. Redistributions of source code must retain the above copyright notice, -/// this list of conditions and the following disclaimer. -/// 2. Redistributions in binary form must reproduce the above copyright notice, -/// this list of conditions and the following disclaimer in the documentation -/// and/or other materials provided with the distribution. -/// 3. Neither the name of the copyright holder nor the -/// names of its contributors may be used to endorse or promote products -/// derived from this software without specific prior written permission. -/// -//////////////////////////////////////////////////////////////////////////////// -/// -/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -/// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -/// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -/// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -/// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -/// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -/// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -/// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -/// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -/// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -/// POSSIBILITY OF SUCH DAMAGE. -/// @endcond -//////////////////////////////////////////////////////////////////////////////// - -#ifndef APE_H -#define APE_H - -// #include <bcm5719_eeprom.h> -// #include <bcm5719_GEN.h> - -// void early_init_hw(void); -// void load_nvm_config(NVRAMContents_t *nvram); -// void init_hw(NVRAMContents_t *nvram); - -#define STATUS_MAIN (0x8234700u) -#define STATUS_EARLY_INIT (0x8234800u) -#define STATUS_NVM_CONFIG (0x8234900u) -#define STATUS_INIT_HW (0x8234A00u) - -// static inline void reportStatus(uint32_t code, uint8_t step) -// { -// GEN.GenDataSig.r32 = (code | step); -// } - - -#endif /* APE_H */ diff --git a/utils/bcmregtool/apeloader/main.c b/utils/bcmregtool/apeloader/main.c index 0aa4c2e..f1e886b 100644 --- a/utils/bcmregtool/apeloader/main.c +++ b/utils/bcmregtool/apeloader/main.c @@ -42,8 +42,6 @@ /// @endcond //////////////////////////////////////////////////////////////////////////////// -#include "ape.h" - #include <APE_SHM.h> int __start() |