Maxim Integrated / OneWire

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Revision:
52:4cba20c21941
Parent:
46:afe466c96069
Child:
53:071ae5d090d1
--- a/OneWire_Masters/GPIO/owlink.s	Mon Apr 11 15:34:22 2016 -0500
+++ b/OneWire_Masters/GPIO/owlink.s	Tue Apr 12 09:08:17 2016 -0500
@@ -1,12 +1,22 @@
+// ow_usdelay configuration
 #define PROC_CLOCK_MHZ (__SYSTEM_HFX / 1000000) // Processor clock in MHz
 #define OVERHEAD_TUNING 21 // Fraction where OverheadTime(us) = OVERHEAD_TUNING / PROC_CLOCK_MHZ
 // Make PROC_CLOCK_MHZ and OVERHEAD_TUNING divisible by PROC_CYCLES_PER_LOOP for best results
 
+// ow_usdelay constants
 #define PIPELINE_REFILL_PROC_CYCLES 1 // ARM specifies 1-3 cycles for pipeline refill following a branch
 #define PROC_CYCLES_PER_LOOP (2 + PIPELINE_REFILL_PROC_CYCLES)
 #define LOOPS_PER_US (PROC_CLOCK_MHZ / PROC_CYCLES_PER_LOOP) // Number of loop passes for a 1 us delay
 #define LOOPS_REMOVED_TUNING (OVERHEAD_TUNING / PROC_CYCLES_PER_LOOP)
 
+// OwTiming offsets
+#define tRSTL_OFFSET    0
+#define tMSP_OFFSET     2
+#define tW0L_OFFSET     4
+#define tW1L_OFFSET     6
+#define tMSR_OFFSET     8
+#define tSLOT_OFFSET   10
+
 // LABEL macro
 #ifdef TOOLCHAIN_GCC_ARM
 #define LABEL(x) x:
@@ -27,7 +37,8 @@
 #else // TOOLCHAIN_IAR or TOOLCHAIN_ARM_STD
 #define THUMB_FUNC
 #endif
- 
+
+// Define a code section
 #if defined TOOLCHAIN_IAR 
   SECTION owlink : CODE
 #elif defined TOOLCHAIN_ARM_STD
@@ -42,16 +53,150 @@
   EXPORT_LABEL(ow_usdelay)
 LABEL(ow_usdelay)
   cmp R0, #0 // Return if time_us equals zero
-  beq return
-  mov R1, #LOOPS_PER_US
-  mul R0, R0, R1
+  beq ow_usdelay_return
+  mov R2, #LOOPS_PER_US
+  mul R0, R0, R2
   sub R0, R0, #LOOPS_REMOVED_TUNING
 LABEL(loop)
   subs R0, R0, #1
   bne loop
-LABEL(return)
+LABEL(ow_usdelay_return)
+  bx R14
+  
+// static void write_ow_gpio_low(unsigned int * portReg, unsigned int pinMask)
+  THUMB_FUNC
+LABEL(write_ow_gpio_low)
+  ldr R2, [R0]
+  bic R2, R2, R1
+  str R2, [R0]
+  bx R14
+  
+// static void write_ow_gpio_high(unsigned int * portReg, unsigned int pinMask)
+  THUMB_FUNC
+LABEL(write_ow_gpio_high)
+  ldr R2, [R0]
+  orr R2, R2, R1
+  str R2, [R0]
+  bx R14
+  
+// static unsigned int read_ow_gpio(unsigned int * portReg, unsigned int pinMask)
+  THUMB_FUNC
+LABEL(read_ow_gpio)
+  ldr R0, [R0]
+  and R0, R0, R1
   bx R14
   
+// void ow_bit(uint8_t * sendrecvbit, const unsigned int * inPortReg, unsigned int * outPortReg, unsigned int pinMask, const OwTiming * timing)
+  THUMB_FUNC
+  EXPORT_LABEL(ow_bit)
+LABEL(ow_bit)
+  push {R4-R8, R14}
+  // Retrive extra parameters from stack
+  add R6, SP, #24 // Find beginning of stack: 6 scratch registers * 4 bytes each
+  ldr R6, [R6] // Load timing struct
+  ldrh R4, [R6, #tSLOT_OFFSET]
+  ldrh R5, [R6, #tMSR_OFFSET]
+  // R0: sendrecvbit
+  // R1: inPortReg
+  // R2: outPortReg
+  // R3: pinMask
+  // R4: tSLOT
+  // R5: tMSR
+  // R6: timing
+  // R7: Scratch
+  // R8: Scratch
+  // R14: Scratch
+  
+  // Reorganize registers for upcoming function calls
+  mov R8, R1 // inPortReg to R8
+  mov R7, R2 // outPortReg to R7
+  mov R1, R3 // pinMask to R1
+  mov R3, R0 // sendrecvbit to R3
+  // R0: Scratch
+  // R1: pinMask
+  // R2: Scratch
+  // R3: sendrecvbit
+  // R4: tSLOT
+  // R5: tMSR
+  // R6: timing
+  // R7: outPortReg
+  // R8: inPortReg
+  // R14: Scratch
+  
+  // if (*sendrecvbit & 1)
+  ldrb R14, [R3]
+  tst R14, #1
+  beq write_zero
+  ldrh R6, [R6, #tW1L_OFFSET] // tW1L
+  sub R4, R4, R5 // tREC = tSLOT - tMSR
+  sub R5, R5, R6 // delay2 = tMSR - tLW1L
+  // R0: Scratch
+  // R1: pinMask
+  // R2: Scratch
+  // R3: sendrecvbit
+  // R4: tREC
+  // R5: delay2
+  // R6: tW1L
+  // R7: outPortReg
+  // R8: inPortReg
+  // R14: Scratch
+  mov R0, R7 // outPortReg
+  bl write_ow_gpio_low // Pull low
+  mov R0, R6 // tLOW
+  bl ow_usdelay // Delay for tLOW
+  mov R0, R7 // outPortReg
+  bl write_ow_gpio_high // Release pin
+  mov R0, R5 // delay2
+  bl ow_usdelay // Delay for sample time
+  mov R0, R8 // inPortReg
+  bl read_ow_gpio // Read pin
+  mov R5, R0 // Store read value for later
+  b recovery_delay
+  // else
+LABEL(write_zero)
+  ldrh R6, [R6, #tW0L_OFFSET] // tW0L
+  sub R4, R4, R6 // tREC = tSLOT - tLW0L
+  sub R6, R6, R5 // delay2 = tW0L - tMSR
+  // R0: Scratch
+  // R1: pinMask
+  // R2: Scratch
+  // R3: sendrecvbit
+  // R4: tREC
+  // R5: tMSR
+  // R6: delay2
+  // R7: outPortReg
+  // R8: inPortReg
+  // R14: Scratch
+  mov R0, R7 // outPortReg
+  bl write_ow_gpio_low // Pull low
+  mov R0, R5 // tMSR
+  bl ow_usdelay // Delay for tMSR
+  mov R0, R8 // inPortReg
+  bl read_ow_gpio // Read pin
+  mov R5, R0 // Store read value for later
+  mov R0, R6 // delay2
+  bl ow_usdelay // Delay for release
+  mov R0, R7 // outPortReg
+  bl write_ow_gpio_high // Release pin
+  // endif (*sendrecvbit & 1)
+  // R0: Scratch
+  // R1: pinMask
+  // R2: Scratch
+  // R3: sendrecvbit
+  // R4: tREC
+  // R5: read value
+  // R6: Scratch
+  // R7: outPortReg
+  // R8: inPortReg
+  // R14: Scratch
+  
+LABEL(recovery_delay)
+  mov R0, R4
+  bl ow_usdelay // Delay for tREC
+  
+  strb R5, [R3]
+  pop {R4-R8, R14}
+  bx R14
 #ifdef TOOLCHAIN_GCC_ARM
   .end
 #else // TOOLCHAIN_IAR or TOOLCHAIN_ARM_STD