Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- struct StepperInterface {
- uint32_t target_pos;
- uint32_t current_pos;
- bool halt_requested;
- };
- far struct StepperInterface shmem __attribute__((location(0x10100))) = {};
- //StepperInterface shmem __attribute__((cregister("LOCAL",near))) = {};
- // define some r30 bits
- #define CW (1u << 0)
- #define CCW (1u << 1)
- volatile register uint32_t __R30;
- #define delay_us(n) __delay_cycles((n) * 200u)
- #define delay_ms(n) delay_us((n) * 1000u)
- static inline void deassert_CW_CCW() { __R30 = 0; }
- static inline void assert_CW() { __R30 = CW; }
- static inline void assert_CCW() { __R30 = CCW; }
- int main() {
- uint32_t pos = shmem.current_pos;
- deassert_CW_CCW();
- delay_us(1);
- while ( !shmem.halt_requested ) {
- int32_t delta = shmem.target_pos - pos;
- if ( delta == 0 )
- continue;
- if ( delta < 0 ) {
- --pos;
- assert_CCW();
- } else {
- ++pos;
- assert_CW();
- }
- shmem.current_pos = pos;
- delay_us(1000);
- deassert_CW_CCW();
- delay_us(1000);
- }
- __halt();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement