Fehler #749 » mainswitch.diff
| include/biwak/flash.h | ||
|---|---|---|
| 47 | 47 |
int m_writePageSize=1; |
| 48 | 48 | |
| 49 | 49 |
public: |
| 50 |
CFlash( address_t address, int size ); |
|
| 50 |
constexpr CFlash( address_t address, int size ) |
|
| 51 |
:m_startAddress( address ) |
|
| 52 |
,m_userAddress( m_startAddress ) |
|
| 53 |
,m_size( size ) |
|
| 54 |
{
|
|
| 55 | ||
| 56 |
} |
|
| 57 | ||
| 51 | 58 |
~CFlash(); |
| 52 | 59 | |
| 53 | 60 |
uint32_t acquireMemory(int size); |
| include/biwak/flash_intern.h | ||
|---|---|---|
| 20 | 20 | |
| 21 | 21 |
//---Own------------------------------ |
| 22 | 22 | |
| 23 |
#include <lepto/lepto.h> // address_t |
|
| 24 |
#include <biwak/flash.h> // address_t |
|
| 23 |
#include <lepto/lepto.h> // address_t |
|
| 24 |
#include <biwak/flash.h> // address_t |
|
| 25 |
#include <biwak/linker_script.h> |
|
| 25 | 26 |
#if defined( STM32 ) |
| 26 | 27 |
#include <HALWrapper/stm32_flash.h> // FLASH_PAGE_SIZE |
| 27 | 28 |
#else |
| ... | ... | |
| 36 | 37 |
//---Defines------------------------------------------------------------------ |
| 37 | 38 | |
| 38 | 39 | |
| 40 |
#define _override override |
|
| 41 |
extern char _start_user_flash; |
|
| 42 | ||
| 39 | 43 | |
| 40 | 44 |
//---Declaration-------------------------------------------------------------- |
| 41 | 45 | |
| 42 | 46 | |
| 43 | 47 |
class CFlashIntern |
| 48 |
#if 1 |
|
| 44 | 49 |
:public CFlash |
| 50 |
#endif |
|
| 45 | 51 |
{
|
| 46 | 52 | |
| 47 | 53 |
private: |
| 48 | 54 | |
| 49 | 55 |
public: |
| 56 |
//constexpr |
|
| 50 | 57 |
CFlashIntern( ); |
| 51 | 58 |
void init(); |
| 52 | 59 |
~CFlashIntern(); |
| ... | ... | |
| 66 | 73 |
#endif |
| 67 | 74 |
} |
| 68 | 75 |
#endif |
| 69 |
virtual int writeData(address_t address, const void *data, int size) override final; |
|
| 76 |
virtual int writeData(address_t address, const void *data, int size) _override final;
|
|
| 70 | 77 |
//#if defined IS_ENABLED( CONFIG_BIWAK_FLASH_32BIT_COMMANDS ) |
| 71 | 78 |
|
| 72 | 79 |
#if defined FLASH_TYPEPROGRAM_WORD |
| ... | ... | |
| 75 | 82 |
virtual int writeData64(address_t address, const void *data, int size); |
| 76 | 83 |
#endif |
| 77 | 84 |
|
| 78 |
virtual int readData(address_t address, void *data, int size) override final; |
|
| 79 |
virtual int erasePage(address_t pageAddr, int count=1) override final; |
|
| 85 |
virtual int readData(address_t address, void *data, int size) _override final;
|
|
| 86 |
virtual int erasePage(address_t pageAddr, int count=1) _override final;
|
|
| 80 | 87 | |
| 81 | 88 |
void clearPER() const; |
| 82 | 89 |
address_t flashStart() const; |
| ... | ... | |
| 85 | 92 |
void eraseUserFlash(); |
| 86 | 93 |
address_t addressToPage( address_t address ) const; |
| 87 | 94 | |
| 88 |
address_t userStart() const; |
|
| 89 |
int userSize() const; |
|
| 95 |
constexpr address_t userStart() const |
|
| 96 |
{
|
|
| 97 |
return( (address_t )&_start_user_flash ); |
|
| 98 |
} |
|
| 99 |
constexpr int userSize() const |
|
| 100 |
{
|
|
| 101 |
return( ( (address_t)FLASH_BASE + (address_t)(void *)&__flash_size ) |
|
| 102 |
- (address_t)userStart() ); |
|
| 103 |
} |
|
| 90 | 104 |
}; |
| 91 | 105 | |
| 92 | 106 | |
| src/flash.cpp | ||
|---|---|---|
| 27 | 27 |
extern char _start_user_flash; |
| 28 | 28 | |
| 29 | 29 | |
| 30 |
CFlash::CFlash( address_t address, int size ) |
|
| 31 |
:m_size( size ) |
|
| 32 |
{
|
|
| 33 |
m_userAddress = m_startAddress = address; |
|
| 34 |
} |
|
| 30 |
//constexpr CFlash::CFlash( address_t address, int size ) |
|
| 35 | 31 | |
| 36 | 32 | |
| 37 | 33 |
CFlash::~CFlash() |
| src/stm32/biwak.cpp | ||
|---|---|---|
| 48 | 48 |
void SystemClock_Config( ); |
| 49 | 49 |
} |
| 50 | 50 | |
| 51 |
extern "C" {
|
|
| 52 |
uint32_t BIWAK_RCC_GetSysClockFreq(); |
|
| 53 |
HAL_StatusTypeDef BIWAK_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct); |
|
| 54 | ||
| 55 |
uint32_t HAL_RCC_GetSysClockFreq(); |
|
| 56 |
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct); |
|
| 57 |
} |
|
| 58 | ||
| 59 |
uint32_t BIWAK_RCC_GetSysClockFreq() |
|
| 60 |
{
|
|
| 61 |
return(48000000); |
|
| 62 |
} |
|
| 63 | ||
| 64 |
HAL_StatusTypeDef BIWAK_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) |
|
| 65 |
{
|
|
| 66 |
return HAL_OK; |
|
| 67 |
} |
|
| 68 | ||
| 69 |
#if 0 |
|
| 70 | ||
| 71 |
HAL_StatusTypeDef XYZ_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) |
|
| 72 |
{
|
|
| 73 |
return HAL_OK; |
|
| 74 |
} |
|
| 75 | ||
| 76 |
uint32_t BIWAK_RCC_GetSysClockFreq() |
|
| 77 |
{
|
|
| 78 |
return(48000000); |
|
| 79 |
} |
|
| 80 | ||
| 81 |
#endif |
|
| 82 | ||
| 51 | 83 |
void biwakInitClock( ) |
| 52 | 84 |
{
|
| 53 | 85 |
#if defined ( MCU_PLATFORM_STM32 ) |
| src/stm32/can.cpp | ||
|---|---|---|
| 759 | 759 |
{
|
| 760 | 760 |
// This can happen when holding MCU via SWD |
| 761 | 761 |
//exception("Full Callback");
|
| 762 |
lWarning("CAN: RX fifo full");
|
|
| 762 |
lWarning( LDS("CRFF", "CAN: RX fifo full") );
|
|
| 763 | 763 |
} |
| 764 | 764 | |
| 765 | 765 |
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan) |
| src/stm32/flash_intern.cpp | ||
|---|---|---|
| 36 | 36 |
extern char _start_user_flash; |
| 37 | 37 | |
| 38 | 38 | |
| 39 |
//constexpr |
|
| 39 | 40 |
CFlashIntern::CFlashIntern( ) |
| 40 | 41 |
//:CFlash((address_t)flashStart() + (address_t)size(), size(), EAcquireDirection::highLow) |
| 41 | 42 |
:CFlash((address_t)userStart(), userSize() ) |
| ... | ... | |
| 474 | 475 |
{
|
| 475 | 476 |
return( (address_t)FLASH_BASE + (address_t)FLASH_SIZE ); |
| 476 | 477 |
} |
| 477 | ||
| 478 |
address_t CFlashIntern::userStart() const |
|
| 478 |
#if 0 |
|
| 479 |
constexpr address_t CFlashIntern::userStart() const
|
|
| 479 | 480 |
{
|
| 480 | 481 |
// when _start_user_flash would not be available: |
| 481 | 482 |
#if 0 |
| ... | ... | |
| 493 | 494 |
#endif |
| 494 | 495 |
} |
| 495 | 496 | |
| 496 |
int CFlashIntern::userSize() const |
|
| 497 |
constexpr int CFlashIntern::userSize() const
|
|
| 497 | 498 |
{
|
| 498 | 499 |
return( |
| 499 | 500 |
//(address_t)size() |
| ... | ... | |
| 506 | 507 |
- (address_t)userStart() ); |
| 507 | 508 |
#endif |
| 508 | 509 |
} |
| 509 | ||
| 510 |
#endif |
|
| 510 | 511 |
void CFlashIntern::eraseUserFlash() |
| 511 | 512 |
{
|
| 512 | 513 |
// Check everything is alligned to pages |
| src/stm32/gpio.cpp | ||
|---|---|---|
| 212 | 212 | |
| 213 | 213 |
CGpio::~CGpio() |
| 214 | 214 |
{
|
| 215 |
/* |
|
| 215 | 216 |
HAL_GPIO_DeInit( peripheralEnumToPeripheral( m_eGpioPeripheral ) |
| 216 | 217 |
, pinEnumToDefine( m_eGpioPin ) ); |
| 218 |
*/ |
|
| 217 | 219 |
} |
| 218 | 220 | |
| 219 | 221 |
void CGpio::setValue(bool _value) const |
| src/stm32/systick.cpp | ||
|---|---|---|
| 39 | 39 |
//---Implementation------------------------------------------------------------ |
| 40 | 40 | |
| 41 | 41 | |
| 42 |
lrtimer_t lrtPerMsec=-1; |
|
| 43 |
int systickCounter=0; |
|
| 42 |
const lrtimer_t lrtPerMsec=1; |
|
| 43 |
// #define lrtPerMsec 1 |
|
| 44 | ||
| 45 |
// int systickCounter=0; |
|
| 44 | 46 | |
| 45 | 47 |
#if ! IS_ENABLED( CONFIG_BIWAK_NO_HRT ) |
| 46 | 48 |
// Fixed point float to increase precission |
| ... | ... | |
| 60 | 62 |
void initSystick( ) |
| 61 | 63 |
{
|
| 62 | 64 |
// How much ticks do we need till one lrtimer-step/1ms is reached? |
| 63 |
systickCounter=( HAL_RCC_GetSysClockFreq() / MSECS_PER_SEC ); |
|
| 65 |
#if 1 |
|
| 66 |
// systickCounter=48000; |
|
| 67 |
#else |
|
| 68 |
systickCounter=( HAL_RCC_GetSysClockFreq() / MSECS_PER_SEC ); |
|
| 69 |
#endif |
|
| 64 | 70 |
|
| 65 | 71 |
// Calling HAL_SYSTICK_Config() and HAL_NVIC_SetPriority() is already done |
| 66 | 72 |
// via HAL_Init(): |
| ... | ... | |
| 86 | 92 |
hrtPerUsec = ( hrtMultiplikator / USECS_PER_MSEC ); |
| 87 | 93 |
#endif |
| 88 | 94 | |
| 89 |
lrtPerMsec = 1;
|
|
| 95 |
/*lrtPerMsec = 1;*/
|
|
| 90 | 96 | |
| 91 | 97 |
// Must have higher priority than anything using timer values. |
| 92 | 98 |
//HAL_NVIC_SetPriority( SysTick_IRQn, NVI_HIGH_PRIORITY, 1); |
| ... | ... | |
| 172 | 178 | |
| 173 | 179 |
#else |
| 174 | 180 | |
| 181 |
/* |
|
| 175 | 182 |
hrtimer_t msecToHrtValue(int mseconds) |
| 176 | 183 |
{
|
| 177 | 184 |
exception( ); |
| 178 | 185 |
return( 0 ); |
| 179 | 186 |
} |
| 187 |
*/ |
|
| 180 | 188 | |
| 181 | 189 |
#endif |
| 182 | 190 | |
| 183 |
int32_t lrtValueToMsec(lrtimer_t lrtValue) |
|
| 191 |
int32_t lrtValueToMsec(const lrtimer_t lrtValue) |
|
| 192 |
{
|
|
| 193 |
return( lrtValue /* / lrtPerMsec */ ); |
|
| 194 |
} |
|
| 195 | ||
| 196 |
lrtimer_t msecToLrt(const int32_t msec) |
|
| 184 | 197 |
{
|
| 185 |
return( lrtValue / lrtPerMsec );
|
|
| 198 |
return( msec /* * lrtPerMsec */ );
|
|
| 186 | 199 |
} |
| 187 | 200 | |
| 188 |
lrtimer_t msecToLrt(int32_t msec) |
|
| 201 |
#if 1 |
|
| 202 |
constexpr int div1000(const int x) |
|
| 189 | 203 |
{
|
| 190 |
return( msec * lrtPerMsec ); |
|
| 204 |
//return (x >> 10) + (x >> 16) + (x >> 17); |
|
| 205 |
// 999,83 |
|
| 206 |
//return( ( x * 4195U ) >> 22 ); |
|
| 207 |
/* |
|
| 208 |
int cnt=0; |
|
| 209 |
while( x ) |
|
| 210 |
{
|
|
| 211 |
x-=1000; |
|
| 212 |
cnt++; |
|
| 213 |
} |
|
| 214 |
return(cnt); |
|
| 215 |
*/ |
|
| 216 |
return( ( ( x >> 3 ) * 131 ) >> 14 ); |
|
| 217 |
// return( x / 1000 ); |
|
| 191 | 218 |
} |
| 219 |
#endif |
|
| 192 | 220 | |
| 193 | 221 |
int32_t lrtValueToSec(lrtimer_t lrtValue) |
| 194 | 222 |
{
|
| 195 |
return( (lrtValue / lrtPerMsec) / MSECS_PER_SEC ); |
|
| 223 |
//return( (lrtValue / lrtPerMsec) / MSECS_PER_SEC ); |
|
| 224 |
//return( lrtValue / MSECS_PER_SEC ); |
|
| 225 |
//static_assert( lrtPerMsec == 1 ); |
|
| 226 |
return( div1000( lrtValue ) ); |
|
| 227 | ||
| 228 |
//int cnt=0; |
|
| 229 |
//while( lrtValue) |
|
| 196 | 230 |
} |
| 197 | 231 | |
| 198 | 232 |
lrtimer_t secToLrt(int32_t sec) |
| ... | ... | |
| 200 | 234 |
return( sec * lrtPerMsec * MSECS_PER_SEC ); |
| 201 | 235 |
} |
| 202 | 236 | |
| 203 |
int usleepLr(useconds_t usecDelayValue
|
|
| 237 |
void usleepLr(useconds_t usecDelayValue
|
|
| 204 | 238 |
#if IS_ENABLED( CONFIG_BIWAK_DATA_EVENT ) |
| 205 | 239 |
, bool breakOnData |
| 206 | 240 |
#endif |
| 207 | 241 |
) |
| 208 | 242 |
{
|
| 209 |
lrtimer_t nowValue; |
|
| 243 |
//lrtimer_t nowValue;
|
|
| 210 | 244 |
lrtimer_t startValue=getLrTimerValue(); |
| 211 | 245 | |
| 212 | 246 |
#if IS_ENABLED( CONFIG_BIWAK_DETECT_NESTED_USLEEP ) |
| ... | ... | |
| 234 | 268 |
pending=false; |
| 235 | 269 |
#endif |
| 236 | 270 |
|
| 237 |
return(0); |
|
| 271 |
return; //(0);
|
|
| 238 | 272 |
} |
| 239 | 273 |
//printf( "DATA: %d/%d\n", biwakDataAvailable, biwakDataAvailableOnLastExit ); |
| 240 | 274 |
#endif |
| 241 | 275 |
|
| 242 |
usecDelayValue/=USECS_PER_MSEC; |
|
| 276 |
//usecDelayValue/=USECS_PER_MSEC; |
|
| 277 |
//usecDelayValue=((uint64_t)usecDelayValue * 0x10624DD3ULL) >> 38; |
|
| 278 |
//(usecDelayValue >> 10) + (usecDelayValue >> 16) + (usecDelayValue >> 17) |
|
| 279 |
/* |
|
| 280 |
static_assert( div1000_fast( 1000 ) == 1 ); |
|
| 281 |
static_assert( div1000_fast( 900 ) == 1 ); |
|
| 282 |
static_assert( div1000_fast( 10000 ) == 10 ); |
|
| 283 |
static_assert( div1000_fast( 234000 ) == 234 ); |
|
| 284 |
static_assert( div1000_fast( 567000 ) == 567 ); |
|
| 285 |
*/ |
|
| 286 |
int msecDelayValue=div1000( usecDelayValue ); |
|
| 287 |
//usecDelayValue/=1000; |
|
| 243 | 288 |
|
| 244 |
while( ( (nowValue=getLrTimerValue()) - startValue)/lrtPerMsec < (int)usecDelayValue )
|
|
| 289 |
while( /*div1000*/( (/*nowValue=*/getLrTimerValue()) - startValue ) < msecDelayValue )
|
|
| 245 | 290 |
{
|
| 246 | 291 |
// Low power modes can not be debugged on L100; Openocd communication |
| 247 | 292 |
// fails |
| ... | ... | |
| 269 | 314 |
pending=false; |
| 270 | 315 |
#endif |
| 271 | 316 |
|
| 272 |
return(0); |
|
| 317 |
return; //(0);
|
|
| 273 | 318 |
} |
| 274 | 319 | |
| 275 | 320 |
#if ! IS_ENABLED( CONFIG_BIWAK_NO_HRT ) |
| ... | ... | |
| 409 | 454 |
#pragma GCC diagnostic pop |
| 410 | 455 |
} |
| 411 | 456 | |
| 457 |
/* |
|
| 412 | 458 |
int getSystickCounter() |
| 413 | 459 |
{
|
| 414 | 460 |
return( systickCounter ); |
| 415 | 461 |
} |
| 416 | ||
| 462 |
*/ |
|
| 417 | 463 | |
| 418 | 464 |
//---fin----------------------------------------------------------------------- |
| include/campo/vagus.hpp | ||
|---|---|---|
| 219 | 219 |
void digestNmtObject( const Tdt::CMessage &msg ); |
| 220 | 220 | |
| 221 | 221 |
#if IS_ENABLED( CONFIG_VAGUS_CUSTOM_DIGEST_SEND_OBJECT ) |
| 222 |
as |
|
| 222 | 223 |
virtual bool digestSendObject( const Tdt::CMessage &msg ) = 0; |
| 223 | 224 |
#else |
| 224 | 225 |
bool digestSendObject( const Tdt::CMessage &msg ); |
| ... | ... | |
| 230 | 231 |
bool digestWriteObjectCustom( const Tdt::CMessage &msg ); |
| 231 | 232 |
#else |
| 232 | 233 |
bool digestWriteObject( const Tdt::CMessage &msg ); |
| 234 |
asd |
|
| 233 | 235 |
virtual bool digestWriteObjectCustom( const Tdt::CMessage &msg ) = 0; |
| 234 | 236 |
#endif |
| 235 | 237 |
#else |
| ... | ... | |
| 237 | 239 |
#endif |
| 238 | 240 |
|
| 239 | 241 |
#if IS_ENABLED( CONFIG_VAGUS_TDT_MMP ) |
| 240 |
void digestMmpObject( const Tdt::CMessage &msg ); |
|
| 241 |
virtual int handleMmpTransfer( const Tdt::CMmpTransferData& transferData ); |
|
| 242 |
void digestMmpObject( const Tdt::CMessage &msg ); |
|
| 243 |
int handleMmpTransfer( const Tdt::CMmpTransferData& transferData ); |
|
| 244 |
#if IS_ENABLED( CONFIG_VAGUS_PSEUDO_VIRTUAL ) |
|
| 245 |
int handleMmpTransferCustom( const Tdt::CMmpTransferData& transferData ); |
|
| 246 |
#else |
|
| 247 |
sd |
|
| 248 |
virtual int handleMmpTransferCustom( const Tdt::CMmpTransferData& transferData ) = 0; |
|
| 249 |
#endif |
|
| 242 | 250 |
#endif |
| 243 | 251 |
|
| 244 | 252 |
#if IS_ENABLED( CONFIG_VAGUS_CUSTOM_SEND_INTRODUCTION ) |
| 253 |
asd |
|
| 245 | 254 |
virtual void sendIntroduction()=0; |
| 255 |
asd |
|
| 246 | 256 |
#else |
| 247 | 257 |
void sendIntroduction(); |
| 248 | 258 |
#endif |
| ... | ... | |
| 253 | 263 |
#if IS_ENABLED( CONFIG_VAGUS_CUSTOM_SEND_CONFIG_PV ) |
| 254 | 264 |
void sendConfigCustom(); |
| 255 | 265 |
#else |
| 266 |
sasd |
|
| 256 | 267 |
virtual void sendConfigCustom() = 0; |
| 257 | 268 |
#endif |
| 258 | 269 |
#endif |
| ... | ... | |
| 304 | 315 |
#endif |
| 305 | 316 | |
| 306 | 317 |
#if IS_ENABLED( CONFIG_VAGUS_CUSTOM_BUS ) |
| 318 |
sdf |
|
| 307 | 319 |
virtual int transmit( const SCanMessage &message ) = 0; |
| 308 | 320 |
#endif |
| 309 | 321 |
|
| src/vagus.cpp | ||
|---|---|---|
| 210 | 210 | |
| 211 | 211 |
#if IS_ENABLED( CONFIG_VAGUS_USE_OPERATINGTIME ) |
| 212 | 212 |
#define OPT_UPDATES_PER_HOUR 4 |
| 213 |
#define OPT_UPDATES_PER_HOUR_SHIFT 2 |
|
| 213 | 214 |
// The value is stored in seconds, but only stored every hour. |
| 214 | 215 |
// lifetime is usually 10⁶ erase/write cycles. Device will run > 100 years |
| 215 |
if( lrElapsedSeconds(&m_lrTimerOperatingTime, SEC_PER_HOUR / OPT_UPDATES_PER_HOUR ) )
|
|
| 216 |
if( lrElapsedSeconds(&m_lrTimerOperatingTime, SEC_PER_HOUR >> OPT_UPDATES_PER_HOUR_SHIFT ) )
|
|
| 216 | 217 |
{
|
| 217 |
VAGUS_CONFIG( operatingTime )+=SEC_PER_HOUR / OPT_UPDATES_PER_HOUR;
|
|
| 218 |
VAGUS_CONFIG( operatingTime )+=SEC_PER_HOUR >> OPT_UPDATES_PER_HOUR_SHIFT;
|
|
| 218 | 219 |
storeConfig(); |
| 219 | 220 |
} |
| 220 | 221 |
#endif |
| ... | ... | |
| 664 | 665 |
} |
| 665 | 666 |
*/ |
| 666 | 667 |
|
| 667 |
lCritical("MMP:NI");
|
|
| 668 |
return(0);
|
|
| 668 |
//lCritical("MMP:NI");
|
|
| 669 |
return( handleMmpTransferCustom( transfer ) );
|
|
| 669 | 670 |
} |
| 670 | 671 | |
| 671 | 672 |
#endif // ? CONFIG_VAGUS_TDT_MMP |
| include/kokon/kokon.hpp | ||
|---|---|---|
| 29 | 29 |
#include <biwak/retain.h> |
| 30 | 30 |
#include <biwak/linker_script.h> |
| 31 | 31 |
#include <biwak/i2c_slave.h> |
| 32 |
#include <biwak/flash_intern.h> |
|
| 32 | 33 |
#include <lepto/log.h> |
| 33 | 34 |
#include <campo/vagus.hpp> |
| 34 | 35 |
#include <tdt/message.hpp> |
| ... | ... | |
| 61 | 62 |
static constexpr const uint8_t APPLICATION_DISABLED = 0xE0; |
| 62 | 63 |
|
| 63 | 64 |
#if IS_ENABLED( CONFIG_KOKON_SEND_EEPROM ) |
| 64 |
char eeprom[0x80];
|
|
| 65 |
char eeprom[0x80]; |
|
| 65 | 66 |
#endif |
| 66 | 67 |
|
| 67 | 68 |
bool m_isReverse; |
| ... | ... | |
| 76 | 77 |
//operator int(){ return((int)this); };
|
| 77 | 78 |
}; |
| 78 | 79 |
int operator =(EErrorCode e){ return((int)e); };
|
| 80 |
CFlashIntern m_flash; |
|
| 79 | 81 |
|
| 80 | 82 |
public: |
| 81 | 83 |
CKokon( ); |
| ... | ... | |
| 86 | 88 |
void bootApplication(); |
| 87 | 89 |
void moveInterrupVectorTable(); |
| 88 | 90 |
void addressInfo(); |
| 91 |
/* |
|
| 89 | 92 |
virtual bool digestWriteObject(const Tdt::CMessage& msg) |
| 90 | 93 |
{
|
| 91 | 94 |
return( false ); |
| ... | ... | |
| 93 | 96 |
virtual void sendConfig() final |
| 94 | 97 |
{
|
| 95 | 98 |
} |
| 96 |
virtual void setDefaultConfig() final /* abstract */ |
|
| 99 |
*/ |
|
| 100 |
#if IS_ENABLED( CONFIG_VAGUS_PSEUDO_VIRTUAL ) |
|
| 101 |
void setDefaultConfig() |
|
| 102 |
#else |
|
| 103 |
virtual void setDefaultConfig() override final |
|
| 104 |
#endif |
|
| 97 | 105 |
{
|
| 98 | 106 |
VAGUS_CONFIG( nodeId ) = 53; |
| 99 | 107 |
} |
| 100 |
int handleMmpTransfer( const Tdt::CMmpTransferData& transferData ) override; |
|
| 108 | ||
| 109 |
#if IS_ENABLED( CONFIG_VAGUS_PSEUDO_VIRTUAL ) |
|
| 110 |
int handleMmpTransfer( const Tdt::CMmpTransferData& transferData ); |
|
| 111 |
#else |
|
| 112 |
virtual int handleMmpTransfer( const Tdt::CMmpTransferData& transferData ) override; |
|
| 113 |
#endif |
|
| 101 | 114 |
//void transferAcknowledge(int sta); |
| 102 | 115 | |
| 103 | 116 |
// Is the bootloader located in application flash area and supposed to |
| src/kokon.cpp | ||
|---|---|---|
| 202 | 202 |
{
|
| 203 | 203 |
lDebug( LDS( "MCMD x%X", "MMP Command: 0x%X"), tdata.header().mmpCommand); |
| 204 | 204 |
|
| 205 |
CFlashIntern flash; |
|
| 206 | 205 |
bool commandForReverse=false; |
| 207 | 206 |
//const Tdt::CMmpTransferData& tdata=transfer.m_data; |
| 208 | 207 |
int sta=(int)EErrorCode::unhandled; |
| ... | ... | |
| 234 | 233 |
} |
| 235 | 234 |
pages= m_workAreaSize / FLASH_PAGE_SIZE; |
| 236 | 235 |
|
| 237 |
sta=flash.erasePage( m_workAreaAddress, pages ); |
|
| 236 |
sta=m_flash.erasePage( m_workAreaAddress, pages );
|
|
| 238 | 237 |
//transferAcknowledge(sta); |
| 239 | 238 |
#endif |
| 240 | 239 |
break; |
| ... | ... | |
| 263 | 262 |
{
|
| 264 | 263 |
dataLen = ( dataLen + 8 ) & ~7; |
| 265 | 264 |
} |
| 266 |
sta=flash.writeData( m_workAreaAddress + tdata.header().flashAddress |
|
| 265 |
sta=m_flash.writeData( m_workAreaAddress + tdata.header().flashAddress
|
|
| 267 | 266 |
,tdata.data(), dataLen ); |
| 268 | 267 |
if(sta) |
| 269 | 268 |
{
|
| ... | ... | |
| 383 | 382 |
} |
| 384 | 383 | |
| 385 | 384 | |
| 385 |
#if IS_ENABLED( CONFIG_VAGUS_PSEUDO_VIRTUAL ) |
|
| 386 | ||
| 387 |
void CVagus::setDefaultConfig() |
|
| 388 |
{
|
|
| 389 |
static_cast<CKokon*>( this )->setDefaultConfig( ); |
|
| 390 |
} |
|
| 391 | ||
| 392 |
int CVagus::handleMmpTransferCustom( const Tdt::CMmpTransferData& transferData ) |
|
| 393 |
{
|
|
| 394 |
return( static_cast<CKokon*>( this )->handleMmpTransfer( transferData ) ); |
|
| 395 |
} |
|
| 396 | ||
| 397 |
#endif |
|
| 398 | ||
| 399 | ||
| 386 | 400 |
//---fin---------------------------------------------------------------------- |
| README.md | ||
|---|---|---|
| 1 | 1 |
libTDT is an CAN based protocol for simple sensor values. |
| 2 | ||
| 3 |
1 | EObject | ENmtObject | mmpSource | |
|
| 4 |
2 | | | | |
|
| 5 |
------------------------------------- |
|
| 6 |
3 | EUnit | mmpPos | |
|
| 7 |
------------------------| | |
|
| 8 |
4 | Reserved | | |
|
| 9 |
------------------------------------- |
|
| 10 |
5 | | |
|
| 11 |
6 | Data | |
|
| 12 |
7 | | |
|
| 13 |
8 | | |
|
| 14 |
------------------------------------- |
|
| arena/apps/mainswitch.json | ||
|---|---|---|
| 7 | 7 |
"comment": "must not disable _ctype_", |
| 8 | 8 |
"symbolMap": [ |
| 9 | 9 |
"vfprintf = lepto_vfprintf", |
| 10 |
"vsnprintf = lepto_vsnprintf" |
|
| 10 |
"vsnprintf = lepto_vsnprintf", |
|
| 11 |
"HAL_RCC_GetSysClockFreq = BIWAK_RCC_GetSysClockFreq", |
|
| 12 |
"HAL_RCC_OscConfig = BIWAK_RCC_OscConfig", |
|
| 13 |
"Xmain = abort" |
|
| 11 | 14 |
], |
| 12 | 15 |
"X": "XHAL_RCC_OscConfig = b_RCC_OscConfig", |
| 13 | 16 |
"periphery": [ |
| ... | ... | |
| 30 | 33 |
"name": "1", |
| 31 | 34 |
"variant": "!Xbootloader" |
| 32 | 35 |
}, |
| 33 |
{
|
|
| 36 |
{
|
|
| 34 | 37 |
"type": "OPTION_BYTES", |
| 35 | 38 |
"name": "1", |
| 36 | 39 |
"variant": "!bootloader" |
| common/config.h | ||
|---|---|---|
| 19 | 19 |
#define CONFIG_LAYOUT_MAJOR 1 |
| 20 | 20 |
#define CONFIG_LAYOUT_MINOR 0 |
| 21 | 21 | |
| 22 |
#define CONFIG_VAGUS_PSEUDO_VIRTUAL 1 |
|
| 23 | ||
| 22 | 24 |
// writing config like node shutdown time |
| 23 | 25 |
#define CONFIG_VAGUS_CUSTOM_DIGEST_WRITE_OBJECT 1 |
| 24 | 26 |
#define CONFIG_VAGUS_CUSTOM_DIGEST_WRITE_OBJECT_PV 1 |
| libbiwak | ||
|---|---|---|
| 1 |
Subproject commit 8c1e9558f3391d24e7b9bda1a667e9da77c7640b |
|
| 1 |
Subproject commit 8c1e9558f3391d24e7b9bda1a667e9da77c7640b-dirty |
|
| libcampo | ||
|---|---|---|
| 1 |
Subproject commit 8af6a6deda6ed8148193de2a2d1a7fd63ab0e966 |
|
| 1 |
Subproject commit 8af6a6deda6ed8148193de2a2d1a7fd63ab0e966-dirty |
|
| libkokon | ||
|---|---|---|
| 1 |
Subproject commit 83ed0a44e92edbcc2460a083001094f9ef389abb |
|
| 1 |
Subproject commit 83ed0a44e92edbcc2460a083001094f9ef389abb-dirty |
|
| libtdt | ||
|---|---|---|
| 1 |
Subproject commit d6a851567089cdf5448560221f8271f785d6f4d5 |
|
| 1 |
Subproject commit d6a851567089cdf5448560221f8271f785d6f4d5-dirty |
|
| mainswitch/include/mainswitch.h | ||
|---|---|---|
| 72 | 72 |
// int reg; |
| 73 | 73 |
int mul; |
| 74 | 74 |
int add; |
| 75 |
int div; |
|
| 75 |
//int div; |
|
| 76 |
int mul2; |
|
| 77 |
int shift; |
|
| 76 | 78 |
}; |
| 77 | 79 |
|
| 78 |
static constexpr SLm25056Value LMTemp{ 0x8d, 100, 14500, 1580 * 10 };
|
|
| 79 |
static constexpr SLm25056Value LMCurr{ 0xd1, 1, 0, 1 };
|
|
| 80 |
static constexpr SLm25056Value LMTemp{ 0x8d, 100, 14500, /* 1580 * 10, */ 1, 1 };
|
|
| 81 |
static constexpr SLm25056Value LMCurr{ 0xd1, 1, 0, /* 1,*/ 1, 1 };
|
|
| 80 | 82 |
// 0xDC is AVG |
| 81 |
static constexpr SLm25056Value LMVolt{ 0x88, 100, 1343, 16296 };
|
|
| 83 |
static constexpr SLm25056Value LMVolt{ 0x88, 100, 1343, /* 16296, */ 263821, 32 };
|
|
| 82 | 84 |
#endif |
| 83 | 85 | |
| 84 | 86 |
private: |
| ... | ... | |
| 126 | 128 |
~CMainSwitch(); |
| 127 | 129 | |
| 128 | 130 |
void prepareApplication(); |
| 129 |
virtual void setDefaultConfig() override final; |
|
| 131 |
#if IS_ENABLED( CONFIG_VAGUS_PSEUDO_VIRTUAL ) |
|
| 132 |
void setDefaultConfig(); |
|
| 133 |
#else |
|
| 134 |
virtual void setDefaultConfig() override final; |
|
| 135 |
#endif |
|
| 130 | 136 |
void eventLoop(); |
| 131 | 137 |
void poweroff() __attribute__((noreturn)); |
| 132 | 138 | |
| mainswitch/src/main.cpp | ||
|---|---|---|
| 23 | 23 |
//---Implementation----------------------------------------------------------- |
| 24 | 24 | |
| 25 | 25 | |
| 26 |
extern "C" {
|
|
| 27 |
void SystemClock_Config( ); |
|
| 28 |
uint32_t BIWAK_RCC_GetSysClockFreq() __attribute__((used)); |
|
| 29 |
uint32_t HAL_RCC_GetSysClockFreq() __attribute__((used)); |
|
| 30 |
HAL_StatusTypeDef BIWAK_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) __attribute__((used)); |
|
| 31 |
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) __attribute__((used)); |
|
| 32 |
} |
|
| 33 | ||
| 34 | ||
| 26 | 35 |
int main(void) |
| 27 | 36 |
{
|
| 28 | 37 |
biwakInitNoClock(); |
| 29 | 38 |
//biwakInit(); |
| 30 | 39 |
//arenaInit(); |
| 40 |
//HAL_RCC_GetSysClockFreq(); |
|
| 31 | 41 | |
| 32 | 42 |
CMainSwitch *pMainSwitch=new CMainSwitch; |
| 43 |
//printf("%d\n", (int)&BIWAK_RCC_OscConfig + (int)&BIWAK_RCC_GetSysClockFreq );
|
|
| 44 |
printf("%d\n", (int)&HAL_RCC_GetSysClockFreq );
|
|
| 45 | ||
| 46 |
//static CMainSwitch mainSwitch; |
|
| 47 |
//CMainSwitch *pMainSwitch=&mainSwitch; |
|
| 48 | ||
| 33 | 49 |
pMainSwitch->prepareApplication(); |
| 34 | 50 | |
| 35 | 51 |
pMainSwitch->appInfo(); |
| mainswitch/src/main_bootloader.cpp | ||
|---|---|---|
| 22 | 22 |
int main(void) |
| 23 | 23 |
{
|
| 24 | 24 |
biwakInit(); |
| 25 |
|
|
| 26 |
CKokon* pKokon=new CKokon; |
|
| 25 | ||
| 26 |
//CKokon kokon; |
|
| 27 |
//CKokon* pKokon=&kokon; |
|
| 28 | ||
| 29 |
static CKokon kokon; |
|
| 30 |
CKokon* pKokon=&kokon; |
|
| 31 | ||
| 32 |
//CKokon* pKokon=new CKokon; |
|
| 27 | 33 | |
| 28 | 34 |
#if ! IS_ENABLED( CONFIG_VAGUS_TDT_MMP ) |
| 29 | 35 |
#error "MMP is not enabled." |
| mainswitch/src/mainswitch.cpp | ||
|---|---|---|
| 338 | 338 |
int value=m_adcLineBattery.accuireAdcValue(); |
| 339 | 339 |
m_outputMeasureEnable.switchOff(); |
| 340 | 340 |
|
| 341 |
int milliVolt = ( value * 3000 ) / 4095; |
|
| 341 |
// int milliVolt = ( value * 3000 ) / 4095; |
|
| 342 |
static_assert( ( ( 4095 + 1 ) * 3000 ) / 4095 == 3000); |
|
| 343 |
int milliVolt = ( ( value + 1 ) * 3000 ) >> 12; |
|
| 342 | 344 |
|
| 343 | 345 |
#if IS_ENABLED( CONFIG_ALERT_VOLTAGES ) |
| 344 | 346 |
if( milliVolt <= MILLIVOLT_BATTERY_WARNING ) |
| ... | ... | |
| 380 | 382 |
*/ |
| 381 | 383 |
value=value16; |
| 382 | 384 |
// printf("RAW[0x%X]: 0x%X\n", v.reg, value16);
|
| 383 |
value = ( ( ( value * v.mul ) + v.add ) * 1000 ) / v.div; |
|
| 385 | ||
| 386 |
//value = ( ( ( value * v.mul ) + v.add ) * 1000 ) / v.div; |
|
| 387 |
value = ( ( ( ( value * v.mul ) + v.add ) * 1000 ) * v.mul2 ) >> v.shift; |
|
| 388 | ||
| 384 | 389 |
sendObject( object, unit, Tdt::SValue{ ._int = value } );
|
| 385 | 390 |
|
| 386 | 391 |
return(value); |
| ... | ... | |
| 519 | 524 |
void CMainSwitch::keepAwake() |
| 520 | 525 |
{
|
| 521 | 526 |
// Extend the new timeout to half of the configured time |
| 522 |
if( lrElapsedSeconds(m_wakeEventTimer) > (int)CUSTOM_CONFIG( shutdownTime )/2 )
|
|
| 527 |
if( lrElapsedSeconds(m_wakeEventTimer) > (int)CUSTOM_CONFIG( shutdownTime ) >> 2 )
|
|
| 523 | 528 |
{
|
| 524 |
m_wakeEventTimer=lrNow() - secToLrt( CUSTOM_CONFIG( shutdownTime ) / 2 );
|
|
| 529 |
m_wakeEventTimer = lrNow() - secToLrt( CUSTOM_CONFIG( shutdownTime ) >> 2 );
|
|
| 525 | 530 |
} |
| 526 | 531 |
} |
| 527 | 532 | |
| ... | ... | |
| 538 | 543 |
#if IS_ENABLED( CONFIG_VAGUS_CUSTOM_DIGEST_WRITE_OBJECT_PV ) |
| 539 | 544 |
bool CVagus::digestWriteObjectCustom( const Tdt::CMessage &msg ) |
| 540 | 545 |
{
|
| 541 |
return( static_cast<CMainSwitch*>( this )->digestWriteObject( msg ) ); |
|
| 546 |
return( static_cast<CMainSwitch*>( this )->digestWriteObjectCustom( msg ) );
|
|
| 542 | 547 |
} |
| 543 | 548 |
#endif |
| 544 | 549 | |
| ... | ... | |
| 551 | 556 |
} |
| 552 | 557 |
#endif |
| 553 | 558 | |
| 559 |
#if IS_ENABLED( CONFIG_VAGUS_PSEUDO_VIRTUAL ) |
|
| 560 |
void CVagus::setDefaultConfig() |
|
| 561 |
{
|
|
| 562 |
static_cast<CMainSwitch*>( this )->setDefaultConfig( ); |
|
| 563 |
} |
|
| 564 |
#endif |
|
| 565 | ||
| 554 | 566 | |
| 555 | 567 |
//---fin---------------------------------------------------------------------- |