rusEFI
The most advanced open source ECU
Typedefs | Functions | Variables
at32_common.cpp File Reference

Detailed Description

Low level common Artery AT32 code.

Date
Oct 29, 2023
Author
Andrey Gusakov, (c) 2023

Definition in file at32_common.cpp.

Typedefs

typedef struct port_intctx intctx_t
 

Functions

int at32GetMcuType (uint32_t id, const char **pn, const char **package, uint32_t *flashSize)
 
int at32GetRamSizeKb (void)
 
static void reset_and_jump (void)
 
void jump_to_bootloader ()
 
void jump_to_openblt ()
 
BOR_Level_t BOR_Get (void)
 
BOR_Result_t BOR_Set (BOR_Level_t BORValue)
 
void startWatchdog (int)
 
void tryResetWatchdog ()
 
void setWatchdogResetPeriod (int)
 
void baseMCUInit (void)
 
bool isStm32F42x (void)
 
EXTERNC int getRemainingStack (thread_t *otp)
 
 __attribute__ ((weak)) void boardPrepareForStandby()
 
Reset_Cause_t getMCUResetCause ()
 
const char * getMCUResetCause (Reset_Cause_t)
 

Variables

uint32_t __main_stack_base__
 

Typedef Documentation

◆ intctx_t

typedef struct port_intctx intctx_t

Definition at line 160 of file at32_common.cpp.

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

Definition at line 186 of file at32_common.cpp.

186  {
187 }

◆ at32GetMcuType()

int at32GetMcuType ( uint32_t  id,
const char **  pn,
const char **  package,
uint32_t *  flashSize 
)

Definition at line 12 of file at32_common.cpp.

13 {
14  const struct {
15  uint32_t uid;
16  const char *pn;
17  uint32_t flashSize;
18  const char *package;
19  } at32f43x_types[] = {
20  { 0x70084540, "AT32F435ZMT7", 4032, "LQFP144" },
21  { 0x70083341, "AT32F435ZGT7", 1024, "LQFP144" },
22  { 0x70084598, "AT32F435ZDT7", 448, "LQFP144" },
23  { 0x70083242, "AT32F435ZCT7", 256, "LQFP144" },
24  { 0x70084543, "AT32F435VMT7", 4032, "LQFP100" },
25  { 0x70083344, "AT32F435VGT7", 1024, "LQFP100" },
26  { 0x70084599, "AT32F435VDT7", 448, "LQFP100" },
27  { 0x70083245, "AT32F435VCT7", 256, "LQFP100" },
28  { 0x70084546, "AT32F435RMT7", 4032, "LQFP64" },
29  { 0x70083347, "AT32F435RGT7", 1024, "LQFP64" },
30  { 0x7008459A, "AT32F435RDT7", 448, "LQFP64" },
31  { 0x70083248, "AT32F435RCT7", 256, "LQFP64" },
32  { 0x70084549, "AT32F435CMT7", 4032, "LQFP48" },
33  { 0x7008334A, "AT32F435CGT7", 1024, "LQFP48" },
34  { 0x7008459B, "AT32F435CDT7", 448, "LQFP48" },
35  { 0x7008324B, "AT32F435CCT7", 256, "LQFP48" },
36  { 0x7008454C, "AT32F435CMU7", 4032, "QFN48" },
37  { 0x7008334D, "AT32F435CGU7", 1024, "QFN48" },
38  { 0x7008459C, "AT32F435CDU7", 448, "QFN48" },
39  { 0x7008324E, "AT32F435CCU7", 256, "QFN48" },
40  { 0x7008454F, "AT32F437ZMT7", 4032, "LQFP144" },
41  { 0x70083350, "AT32F437ZGT7", 1024, "LQFP144" },
42  { 0x7008459D, "AT32F437ZDT7", 448, "LQFP144" },
43  { 0x70083251, "AT32F437ZCT7", 256, "LQFP144" },
44  { 0x70084552, "AT32F437VMT7", 4032, "LQFP100" },
45  { 0x70083353, "AT32F437VGT7", 1024, "LQFP100" },
46  { 0x7008459E, "AT32F437VDT7", 448, "LQFP100" },
47  { 0x70083254, "AT32F437VCT7", 256, "LQFP100" },
48  { 0x70084555, "AT32F437RMT7", 4032, "LQFP64" },
49  { 0x70083356, "AT32F437RGT7", 1024, "LQFP64" },
50  { 0x7008459F, "AT32F437RDT7", 448, "LQFP64" },
51  { 0x70083257, "AT32F437RCT7", 256, "LQFP64" },
52  };
53 
54  for (size_t i = 0; i < efi::size(at32f43x_types); i++) {
55  if (id == at32f43x_types[i].uid) {
56  if (pn)
57  *pn = at32f43x_types[i].pn;
58  if (package)
59  *package = at32f43x_types[i].package;
60  if (flashSize)
61  *flashSize = at32f43x_types[i].flashSize;
62  return 0;
63  }
64  }
65 
66  /* unknown */
67  return -1;
68 }
static uint16_t flashSize()
Definition: mpu_util.cpp:17
composite packet size

Referenced by sayHello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ at32GetRamSizeKb()

int at32GetRamSizeKb ( void  )

Definition at line 70 of file at32_common.cpp.

71 {
72  uint8_t EOPB0 = *(__IO uint16_t *) (0x1FFFC010);
73  /* TODO: check inverted value */
74 
75  switch ((*(__IO uint16_t *) (FLASHSIZE_BASE))) {
76  case 256:
77  EOPB0 &= 0x03;
78  if (EOPB0 == 3)
79  EOPB0 = 2;
80  return 512 - (64 * EOPB0);
81  case 448:
82  EOPB0 &= 0x07;
83  if (EOPB0 > 5)
84  EOPB0 = 5;
85  return 512 - (64 * EOPB0);
86  case 1024:
87  case 4032:
88  EOPB0 &= 0x07;
89  if (EOPB0 > 6)
90  EOPB0 = 6;
91  return 512 - (64 * EOPB0);
92  default:
93  return 0;
94  }
95  return 0;
96 }

Referenced by sayHello().

Here is the caller graph for this function:

◆ baseMCUInit()

void baseMCUInit ( void  )

Definition at line 146 of file at32_common.cpp.

146  {
147  // looks like this holds a random value on start? Let's set a nice clean zero
148  DWT->CYCCNT = 0;
149 
150  BOR_Set(BOR_Level_1); // one step above default value
151 }
BOR_Result_t BOR_Set(BOR_Level_t BORValue)
@ BOR_Level_1
Definition: port_mpu_util.h:21

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BOR_Get()

BOR_Level_t BOR_Get ( void  )

Definition at line 126 of file at32_common.cpp.

126  {
127  /* TODO: Artery */
128  /* Fake */
129  return BOR_Level_None;
130 }
@ BOR_Level_None
Definition: port_mpu_util.h:20

◆ BOR_Set()

BOR_Result_t BOR_Set ( BOR_Level_t  BORValue)

Definition at line 132 of file at32_common.cpp.

132  {
133  /* NOP */
134  return BOR_Result_Ok;
135 }
@ BOR_Result_Ok
Definition: mpu_util.h:93

Referenced by baseMCUInit(), and setBor().

Here is the caller graph for this function:

◆ getMCUResetCause() [1/2]

Reset_Cause_t getMCUResetCause ( )

Definition at line 189 of file at32_common.cpp.

189  {
190  return Reset_Cause_Unknown;
191 }
@ Reset_Cause_Unknown
Definition: mpu_util.h:102

Referenced by checkLastResetCause().

Here is the caller graph for this function:

◆ getMCUResetCause() [2/2]

const char* getMCUResetCause ( Reset_Cause_t  cause)

Definition at line 193 of file at32_common.cpp.

193  {
194  return "Unknown";
195 }

◆ getRemainingStack()

EXTERNC int getRemainingStack ( thread_t *  otp)

Of note is that interrupts are NOT serviced on the stack of the thread that was running when the interrupt occurred. The only thing that happens on that thread's stack is that its registers are pushed (by hardware) when an interrupt occurs, just before swapping the stack pointer out for the main stack (currently 0x400=1024 bytes), where the ISR actually runs. see also main_stack_size see also process_stack_size

see also http://www.chibios.org/dokuwiki/doku.php?id=chibios:kb:stacks

In the firmware we are using 'extern *Engine' - in the firmware Engine is a singleton

On the other hand, in order to have a meaningful unit test we are passing Engine * engine as a parameter

Definition at line 164 of file at32_common.cpp.

164  {
165 #if CH_DBG_ENABLE_STACK_CHECK
166  // this would dismiss coverity warning - see http://rusefi.com/forum/viewtopic.php?f=5&t=655
167  // coverity[uninit_use]
168  register intctx_t *r13 asm ("r13");
169  otp->activeStack = r13;
170 
171  int remainingStack;
172  if (ch0.dbg.isr_cnt > 0) {
173  // ISR context
174  remainingStack = (int)(r13 - 1) - (int)&__main_stack_base__;
175  } else {
176  remainingStack = (int)(r13 - 1) - (int)otp->wabase;
177  }
178  otp->remainingStack = remainingStack;
179  return remainingStack;
180 #else
181  UNUSED(otp);
182  return 99999;
183 #endif /* CH_DBG_ENABLE_STACK_CHECK */
184 }
uint32_t __main_stack_base__
struct port_intctx intctx_t
UNUSED(samplingTimeSeconds)

◆ isStm32F42x()

bool isStm32F42x ( void  )

Definition at line 156 of file at32_common.cpp.

156  {
157  return false;
158 }

Referenced by sayHello(), and startLua().

Here is the caller graph for this function:

◆ jump_to_bootloader()

void jump_to_bootloader ( )

Definition at line 106 of file at32_common.cpp.

106  {
107  // leave DFU breadcrumb which assembly startup code would check, see [rusefi][DFU] section in assembly code
108 
109  *((unsigned long *)0x2001FFF0) = 0xDEADBEEF; // End of RAM
110 
111  reset_and_jump();
112 }
static void reset_and_jump(void)

Referenced by executeTSCommand(), and runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ jump_to_openblt()

void jump_to_openblt ( )

Definition at line 115 of file at32_common.cpp.

115  {
116 #if EFI_USE_OPENBLT
117  /* safe to call on already inited shares area */
119  /* Store sing to stay in OpenBLT */
120  SharedParamsWriteByIndex(0, 0x01);
121 
122  reset_and_jump();
123 #endif
124 }
bool SharedParamsWriteByIndex(uint32_t idx, uint8_t value)
Writes a data byte to the shared parameter buffer at the specified index.
void SharedParamsInit(void)
Initializes the shared RAM parameters module.
Definition: shared_params.c:83

Referenced by executeTSCommand(), processCanRxMessage(), and runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_and_jump()

static void reset_and_jump ( void  )
static

Definition at line 100 of file at32_common.cpp.

100  {
101  // and now reboot
102  NVIC_SystemReset();
103 }

Referenced by jump_to_bootloader(), and jump_to_openblt().

Here is the caller graph for this function:

◆ setWatchdogResetPeriod()

void setWatchdogResetPeriod ( int  resetMs)

Definition at line 143 of file at32_common.cpp.

143  {
144 }

Referenced by initializeConsole().

Here is the caller graph for this function:

◆ startWatchdog()

void startWatchdog ( int  timeoutMs)

Definition at line 137 of file at32_common.cpp.

137  {
138 }

Referenced by initializeConsole(), and writeToFlashNow().

Here is the caller graph for this function:

◆ tryResetWatchdog()

void tryResetWatchdog ( )

Definition at line 140 of file at32_common.cpp.

140  {
141 }

Referenced by doPeriodicSlowCallback().

Here is the caller graph for this function:

Variable Documentation

◆ __main_stack_base__

uint32_t __main_stack_base__
extern

Referenced by getRemainingStack().

Go to the source code of this file.