forked from emmebrusa/TSDZ2-Smart-EBike-1
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Measure ISR load, cleaned up timers, added tuned delay functions, add…
… STMStudio setup and basic layout
- Loading branch information
Showing
9 changed files
with
308 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* delay utilite for STM8 family | ||
* COSMIC and SDCC | ||
* Terentiev Oleg | ||
* [email protected] | ||
*/ | ||
|
||
#ifndef UTIL_DELAY_H_ | ||
#define UTIL_DELAY_H_ 1 | ||
|
||
#ifndef F_CPU | ||
#error F_CPU is not defined! | ||
#endif | ||
|
||
// Amount of cycles was tuned to use desired amount time. | ||
// Compiler settings may affect the delay time precision. | ||
#if defined(__CSMC__) | ||
static @inline void delay_cycl( unsigned short _ticks ) | ||
#else | ||
static inline void delay_cycl( unsigned short _ticks ) | ||
#endif | ||
{ | ||
#if defined(__CSMC__) | ||
/* COSMIC */ | ||
#define T_COUNT_US(x) ((( (x) * (F_CPU / 1000000UL) )-3U)/3U) | ||
// ldw X, ticks ; insert automaticaly | ||
_asm("nop\n $N:\n decw X\n jrne $L\n nop\n ", ticks); | ||
#elif defined(_SDCC_) | ||
#define T_COUNT_US(x) ((( (x) * (F_CPU / 1000000UL) )-4U)*4/15U) | ||
__asm__("nop\n nop\n"); | ||
do { // ASM: lab$: decw X; tnzw X; jrne lab$ | ||
_ticks--;// 1c; + 2c + ; 1/2c + 1/4 (mystery) = 3.75 = 15/4 | ||
} while ( _ticks ); | ||
__asm__("nop\n"); | ||
#elif defined(__RCST7__) | ||
/* RAISONANCE */ | ||
#error ToDo for RAISONANCE | ||
#elif defined(__ICCSTM8__) | ||
/* IAR */ | ||
#error ToDo for IAR | ||
#else | ||
#error Unsupported Compiler! /* Compiler defines not found */ | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Delays for a specified number of microseconds. | ||
* | ||
* Blocking delay. | ||
* | ||
* @param _us the number of microseconds to delay, min = 4, max = 1000 | ||
* | ||
* @return void | ||
* | ||
* @throws None | ||
*/ | ||
static inline void delay_us( unsigned short _us ) | ||
{ | ||
delay_cycl( (unsigned short)( T_COUNT_US(_us) )); | ||
} | ||
|
||
/** | ||
* Delays for a specified number of miliseconds. | ||
* Blocking delay | ||
* | ||
* @param _us the number of microseconds to delay | ||
* | ||
* @return void | ||
* | ||
* @throws None | ||
*/ | ||
static inline void delay_ms( unsigned short _ms ) | ||
{ | ||
while ( _ms-- ) | ||
{ | ||
delay_us( 1000 ); | ||
} | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.