Source File 1 : 'pru_generic.p' (77 Instructions Generated)

    1 :                   : //----------------------------------------------------------------------//
    2 :                   : // Description: pru.main.p                                              //
    3 :                   : // PRU code implementing the main task loop and routines useful for all //
    4 :                   : // task types                                                           //
    5 :                   : //                                                                      //
    6 :                   : // Author(s): Charles Steinkuehler                                      //
    7 :                   : // License: GNU GPL Version 2.0 or (at your option) any later version.  //
    8 :                   : //                                                                      //
    9 :                   : // Major Changes:                                                       //
   10 :                   : // 2013-May    Charles Steinkuehler                                     //
   11 :                   : //             Split into several files                                 //
   12 :                   : //             Altered main loop to support a linked list of tasks      //
   13 :                   : //             Added support for GPIO pins in addition to PRU outputs   //
   14 :                   : // 2012-Dec-27 Charles Steinkuehler                                     //
   15 :                   : //             Initial version                                          //
   16 :                   : //----------------------------------------------------------------------//
   17 :                   : // This file is part of LinuxCNC HAL                                    //
   18 :                   : //                                                                      //
   19 :                   : // Copyright (C) 2012  Charles Steinkuehler                             //
   20 :                   : //                     <charles AT steinkuehler DOT net>                //
   21 :                   : //                                                                      //
   22 :                   : // This program is free software; you can redistribute it and/or        //
   23 :                   : // modify it under the terms of the GNU General Public License          //
   24 :                   : // as published by the Free Software Foundation; either version 2       //
   25 :                   : // of the License, or (at your option) any later version.               //
   26 :                   : //                                                                      //
   27 :                   : // This program is distributed in the hope that it will be useful,      //
   28 :                   : // but WITHOUT ANY WARRANTY; without even the implied warranty of       //
   29 :                   : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
   30 :                   : // GNU General Public License for more details.                         //
   31 :                   : //                                                                      //
   32 :                   : // You should have received a copy of the GNU General Public License    //
   33 :                   : // along with this program; if not, write to the Free Software          //
   34 :                   : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA        //
   35 :                   : // 02110-1301, USA.                                                     //
   36 :                   : //                                                                      //
   37 :                   : // THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR       //
   38 :                   : // ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE   //
   39 :                   : // TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of      //
   40 :                   : // harming persons must have provisions for completely removing power   //
   41 :                   : // from all motors, etc, before persons enter any danger area.  All     //
   42 :                   : // machinery must be designed to comply with local and national safety  //
   43 :                   : // codes, and the authors of this software can not, and do not, take    //
   44 :                   : // any responsibility for such compliance.                              //
   45 :                   : //                                                                      //
   46 :                   : // This code was written as part of the LinuxCNC project.  For more     //
   47 :                   : // information, go to www.linuxcnc.org.                                 //
   48 :                   : //----------------------------------------------------------------------//
   49 :                   : 
   50 :                   : #include "pru.h"
   51 :                   : #include "pru_tasks.h"
   52 :                   : 
   53 :                   : // Register Usage:
   54 :                   : // r0   Scratch / bn count value for LBBO/SBBO/LBCO/SBCO/XIN/XOUT/XCHG/SXIN/SXOUT/SXCHG / XFR Shift Value
   55 :                   : // r1   Scratch / Register pointers for MVIx instructions
   56 :                   : // r2   Scratch
   57 :                   : // r3   Scratch
   58 :                   : // r4   Task Data (task specific use)
   59 :                   : // r5   Task Data (task specific use)
   60 :                   : // r6   Task Data (task specific use)
   61 :                   : // r7   Task Data (task specific use)
   62 :                   : // r8   Task Data (task specific use)
   63 :                   : // r9   Task Data (task specific use)
   64 :                   : // r10  Task Data (task specific use)
   65 :                   : // r11  Task Data (task specific use)
   66 :                   : // r12  TASK_STATUS
   67 :                   : // r13  TASK_ADDR
   68 :                   : // r14  GPIO0_Set
   69 :                   : // r15  GPIO0_Clr
   70 :                   : // r16  GPIO1_Set
   71 :                   : // r17  GPIO1_Clr
   72 :                   : // r18  GPIO2_Set
   73 :                   : // r19  GPIO2_Clr
   74 :                   : // r20  GPIO3_Set
   75 :                   : // r21  GPIO3_Clr
   76 :                   : // r22  PRU_Out
   77 :                   : // r23  Scratch / Reserved (PRU_Out_Remote)
   78 :                   : // r24  Call Register
   79 :                   : // r25  Scratch / Reserved (Multiplier mode/status)
   80 :                   : // r26  Scratch / Reserved (Multiplier Lower product)
   81 :                   : // r27  Scratch / Reserved (Multiplier Upper product)
   82 :                   : // r28  Scratch / Reserved (Multiplier Operand)
   83 :                   : // r29  Scratch / Reserved (Multiplier Operand)
   84 :                   : // r30  Direct Outputs
   85 :                   : // r31  Direct Inputs / Event Generation
   86 :                   : 
   87 :                   : // Leave r30 available for use as direct I/O
   88 :                   : .setcallreg r24.w2
   89 :                   : 
   90 :                   : #define STATE_SIZE  8
   91 :                   : #define NUMCHAN     3
   92 :                   : 
   93 :                   : .struct global_state
   94 :                   :     .u32    Scratch0
   95 :                   :     .u32    Scratch1
   96 :                   :     .u32    Scratch2
   97 :                   :     .u32    Scratch3
   98 :                   :     .u32    State_Reg0
   99 :                   :     .u32    State_Reg1
  100 :                   :     .u32    State_Reg2
  101 :                   :     .u32    State_Reg3
  102 :                   :     .u32    State_Reg4
  103 :                   :     .u32    State_Reg5
  104 :                   :     .u32    State_Reg6
  105 :                   :     .u32    State_Reg7
  106 :                   :     .u32    Task_Status
  107 :                   :     .u32    Task_Addr
  108 :                   :     .u32    GPIO0_Clr
  109 :                   :     .u32    GPIO0_Set
  110 :                   :     .u32    GPIO1_Clr
  111 :                   :     .u32    GPIO1_Set
  112 :                   :     .u32    GPIO2_Clr
  113 :                   :     .u32    GPIO2_Set
  114 :                   :     .u32    GPIO3_Clr
  115 :                   :     .u32    GPIO3_Set
  116 :                   :     .u32    PRU_Out
  117 :                   :     .u16    TaskTable
  118 :                   :     .u16    PinTable
  119 :                   :     .u32    Call_Reg
  120 :                   :     .u32    Mul_Status
  121 :                   :     .u32    Mul_Prod_L
  122 :                   :     .u32    Mul_Prod_H
  123 :                   :     .u32    Mul_Op1
  124 :                   :     .u32    Mul_Op2
  125 :                   : .ends
  126 :                   : 
  127 :                   : .assign global_state, r0, r29, GState
  128 :                   : 
  129 :                   : // Overlay task header onto proper GState registers
  130 :                   : .assign task_header, r12, r13, GTask
  131 :                   : 
  132 :                   : .origin 0
  133 :                   : .entrypoint START
  134 :                   : 
  135 :                   : // PRU GPIO Write Timing Details
  136 :                   : // The actual write instruction to a GPIO pin using SBBO takes two 
  137 :                   : // PRU cycles (10 nS).  However, the GPIO logic can only update every 
  138 :                   : // 40 nS (8 PRU cycles).  This meas back-to-back writes to GPIO pins 
  139 :                   : // will eventually stall the PRU, or you can execute 6 PRU instructions 
  140 :                   : // for 'free' when burst writing to the GPIO.
  141 :                   : //
  142 :                   : // Latency from the PRU write to the actual I/O pin changing state
  143 :                   : // (normalized to PRU direct output pins = zero latency) when the
  144 :                   : // PRU is writing to GPIO1 and L4_PERPort1 is idle measures 
  145 :                   : // 95 nS or 105 nS (apparently depending on clock synchronization)
  146 :                   : //
  147 :                   : // PRU GPIO Posted Writes
  148 :                   : // When L4_PERPort1 is idle, it is possible to burst-write multiple
  149 :                   : // values to the GPIO pins without stalling the PRU, as the writes 
  150 :                   : // are posted.  With an unrolled loop (SBBO to GPIO followed by a 
  151 :                   : // single SET/CLR to R30), the first 20 write cycles (both 
  152 :                   : // instructions) took 15 nS each, at which point the PRU began
  153 :                   : // to stall and the write cycle settled in to the 40 nS maximum
  154 :                   : // update frequency.
  155 :                   : //
  156 :                   : // PRU GPIO Read Timing Details
  157 :                   : // Reading from a GPIO pin when L4_PERPort1 is idle require 165 nS as
  158 :                   : // measured using direct PRU I/O updates bracking a LBBO instruction.
  159 :                   : // Since there is no speculative execution on the PRU, it is not possible
  160 :                   : // to execute any instructions during this time, the PRU just stalls.
  161 :                   : //
  162 :                   : // Latency from the physical I/O pin to the PRU read seeing valid data
  163 :                   : // has not yet been measured.
  164 :                   : 
  165 :                   : START:
  166 : 0x0000 0x2eff3b80 :     FILL    &GState, SIZE(GState)
  167 :                   : 
  168 :                   :     // Clear syscfg[standby_init] to enable ocp master port
  169 : 0x0001 0x91042480 :     LBCO    r0, CONST_PRUCFG, 4, 4
  170 : 0x0002 0x1d04e0e0 :     CLR     r0, r0, 4
  171 : 0x0003 0x81042480 :     SBCO    r0, CONST_PRUCFG, 4, 4
  172 :                   : 
  173 :                   :     // Clear all outputs
  174 : 0x0004 0x240000fe :     LDI     r30, 0
  175 :                   : 
  176 :                   :     // Setup IEP timer
  177 : 0x0005 0x95407a86 :     LBCO    r6, CONST_IEP, 0x40, 40                 // Read all 10 32-bit CMP registers into r6-r15
  178 : 0x0006 0x1303e6e6 :     OR      r6, r6, 0x03                            // Set count reset and enable compare 0 event
  179 :                   : 
  180 :                   :     // Use Task_Addr to point to static variables during init
  181 : 0x0007 0x240000ed :     MOV     GState.Task_Addr, PRU_DATA_START
  182 :                   : 
  183 :                   :     // Load loop period from static variables into CMP0
  184 : 0x0008 0xf1082d88 :     LBBO    r8, GState.Task_Addr, OFFSET(pru_statics.period), SIZE(pru_statics.period)
  185 :                   : 
  186 : 0x0009 0x85407a86 :     SBCO    r6, CONST_IEP, 0x40, 40                 // Save 10 32-bit CMP registers
  187 :                   : 
  188 : 0x000a 0x240551e2 :     MOV     r2, 0x00000551                          // Enable counter, configured to count nS (increments by 5 each clock)
  189 : 0x000b 0x81003a82 :     SBCO    r2, CONST_IEP, 0x00, 4                  // Save IEP GLOBAL_CFG register
  190 :                   : 
  191 :                   :     // Setup registers
  192 :                   : 
  193 :                   :     // Zero all output registers
  194 : 0x000c 0x2eff918e :     ZERO    &GState.GPIO0_Clr, OFFSET(GState.TaskTable) - OFFSET(GState.GPIO0_Clr)
  195 :                   : 
  196 :                   :     // Setup Scratch-Pad 0 with GPIO addresses
  197 : 0x000d 0x2444e0c4 :     MOV     GState.State_Reg0, GPIO0 + GPIO_CLEARDATAOUT
      : 0x000e 0x24719084 : 
  198 : 0x000f 0x244804c5 :     MOV     GState.State_Reg1, GPIO1 + GPIO_CLEARDATAOUT
      : 0x0010 0x24c19085 : 
  199 : 0x0011 0x24481ac6 :     MOV     GState.State_Reg2, GPIO2 + GPIO_CLEARDATAOUT
      : 0x0012 0x24c19086 : 
  200 : 0x0013 0x24481ac7 :     MOV     GState.State_Reg3, GPIO3 + GPIO_CLEARDATAOUT
      : 0x0014 0x24e19087 : 
  201 : 0x0015 0x2f050784 :     XOUT    10, GState.State_Reg0, 16
  202 : 0x0016 0x2eff8784 :     ZERO    &GState.State_Reg0, 16
  203 :                   : 
  204 : 0x0017 0x24004597 :     LDI     GState.TaskTable, #TASKTABLE                // Base address of jump tables
  205 : 0x0018 0x240025d7 :     LDI     GState.PinTable, #PINTABLE
  206 :                   : 
  207 :                   :     // Load start of task list from static variables
  208 : 0x0019 0xf1042d8d :     LBBO    GState.Task_Addr, GState.Task_Addr, OFFSET(pru_statics.addr), SIZE(pru_statics.addr)
  209 :                   : 
  210 :                   : MAINLOOP:
  211 :                   :     // Read task details (Mode, Len, DataX, DataY)
  212 : 0x001a 0xf1002d8c :     LBBO    GState.Task_Status, GTask.addr, OFFSET(task_header.mode), SIZE(GState.Task_Status)
  213 :                   : 
  214 :                   :     // Make sure mode is valid or we could fall off the end of the jump table!
  215 : 0x001b 0x49080c03 :     QBLT    NEXT_TASK, GTask.mode, TASKTABLEEND - TASKTABLE
  216 :                   : 
  217 :                   :     // Index into the jump table and call the routine appropriate for our mode
  218 : 0x001c 0x000c97e1 :     ADD     r1, GState.TaskTable, GTask.mode
  219 : 0x001d 0x20e10000 :     JMP     r1
  220 :                   : 
  221 :                   : NEXT_TASK:
  222 :                   :     // Load the next task address
  223 : 0x001e 0xf1042d8d :     LBBO    GTask.addr, GTask.addr, OFFSET(task_header.addr), SIZE(task_header.addr)
  224 :                   : 
  225 :                   :     // ...and keep going!
  226 : 0x001f 0x21001a00 :     JMP     MAINLOOP
  227 :                   : 
  228 :                   : SET_CLR_BIT:
  229 :                   :     // Manipulate passed parameters into an even value from 0-30 to use to
  230 :                   :     // index into the pin jump table:
  231 :                   :     // Bit:    7  6  5  4  3  2  1  0
  232 :                   :     // Value:  0  0  0  T  T  T  S  0
  233 :                   :     //   T = Target register, S = Set_Clear
  234 :                   : 
  235 : 0x0020 0x09070343 :     LSL     r3.b2, r3.b0, 7
  236 : 0x0021 0x0b052363 :     LSR     r3.b3, r3.b1, 5
  237 : 0x0022 0x0b06c303 :     LSR     r3.b0, r3.w2, 6
  238 :                   :     
  239 : 0x0023 0x0003d7c3 :     ADD     r3.w2, GState.PinTable, r3.b0
  240 : 0x0024 0x20c30000 :     JMP     r3.w2
  241 :                   : 
  242 :                   : PINTABLE:
  243 : 0x0025 0x20d80000 :     RET
  244 : 0x0026 0x20d80000 :     RET
  245 : 0x0027 0x20d80000 :     RET
  246 : 0x0028 0x20d80000 :     RET
  247 :                   : 
  248 : 0x0029 0x1e23eeee :     SET     GState.GPIO0_Clr, GState.Scratch3.b1
  249 : 0x002a 0x20d80000 :     RET
  250 : 0x002b 0x1e23efef :     SET     GState.GPIO0_Set, GState.Scratch3.b1
  251 : 0x002c 0x20d80000 :     RET
  252 :                   : 
  253 : 0x002d 0x1e23f0f0 :     SET     GState.GPIO1_Clr, GState.Scratch3.b1
  254 : 0x002e 0x20d80000 :     RET
  255 : 0x002f 0x1e23f1f1 :     SET     GState.GPIO1_Set, GState.Scratch3.b1
  256 : 0x0030 0x20d80000 :     RET
  257 :                   : 
  258 : 0x0031 0x1e23f2f2 :     SET     GState.GPIO2_Clr, GState.Scratch3.b1
  259 : 0x0032 0x20d80000 :     RET
  260 : 0x0033 0x1e23f3f3 :     SET     GState.GPIO2_Set, GState.Scratch3.b1
  261 : 0x0034 0x20d80000 :     RET
  262 :                   : 
  263 : 0x0035 0x1e23f4f4 :     SET     GState.GPIO3_Clr, GState.Scratch3.b1
  264 : 0x0036 0x20d80000 :     RET
  265 : 0x0037 0x1e23f5f5 :     SET     GState.GPIO3_Set, GState.Scratch3.b1
  266 : 0x0038 0x20d80000 :     RET
  267 :                   : 
  268 : 0x0039 0x1c23f6f6 :     CLR     GState.PRU_Out,   GState.Scratch3.b1
  269 : 0x003a 0x20d80000 :     RET
  270 : 0x003b 0x1e23f6f6 :     SET     GState.PRU_Out,   GState.Scratch3.b1
  271 : 0x003c 0x20d80000 :     RET
  272 :                   : 
  273 : 0x003d 0x20d80000 :     RET
  274 : 0x003e 0x20d80000 :     RET
  275 : 0x003f 0x20d80000 :     RET
  276 : 0x0040 0x20d80000 :     RET
  277 :                   : 
  278 : 0x0041 0x20d80000 :     RET
  279 : 0x0042 0x20d80000 :     RET
  280 : 0x0043 0x20d80000 :     RET
  281 : 0x0044 0x20d80000 :     RET
  282 :                   : PINTABLEEND:
  283 :                   : 
  284 :                   : TASKTABLE:
  285 : 0x0045 0x21001e00 :     JMP     NEXT_TASK           // MODE_NONE
  286 : 0x0046 0x21004d00 :     JMP     MODE_WAIT
  287 : 0x0047 0x21001e00 :     JMP     NEXT_TASK           //     JMP     MODE_WRITE
  288 : 0x0048 0x21001e00 :     JMP     NEXT_TASK           //     JMP     MODE_READ
  289 : 0x0049 0x21005f00 :     JMP     MODE_STEP_DIR
  290 : 0x004a 0x21001e00 :     JMP     NEXT_TASK           //     JMP     MODE_UP_DOWN
  291 : 0x004b 0x21008d00 :     JMP     MODE_DELTA_SIG
  292 : 0x004c 0x21009f00 :     JMP     MODE_PWM
  293 :                   : TASKTABLEEND:
  294 :                   : 
  295 :                   : #include "pru_wait.p"
  296 :                   : // #include "pru_write.p"
  297 :                   : // #include "pru_read.p"
  298 :                   : #include "pru_stepdir.p"
  299 :                   : // #include "pru_updown.p"
  300 :                   : #include "pru_deltasigma.p"
  301 :                   : #include "pru_pwm.p"
  302 :                   : 
  303 :                   : // BeagleBone PRU I/O Assignments
  304 :                   : //
  305 :                   : // There is also a nice table available on github: https://github.com/selsinork/beaglebone-black-pinmux
  306 :                   : //
  307 :                   : //  AM3359ZCZ           Mux                         BeagleBone
  308 :                   : //  Pin Name            Value   PRU I/O Pin         Pin     Name        BeBoPr Use
  309 :                   : //  ------------------------------------------------------------------------------
  310 :                   : //  A13 mcasp0_aclkx    5       pru0.r30.0          P9.31	SPI1_SCLK
  311 :                   : //                      6       pru0.r31.0
  312 :                   : //  B13 mcasp0_fsx      5       pru0.r30.1          P9.29	SPI1_D0
  313 :                   : //                      6       pru0.r31.1
  314 :                   : //  D12 mcasp0_axr0     5       pru0.r30.2          P9.30	SPI1_D1
  315 :                   : //                      6       pru1.r31.2
  316 :                   : //  C12 mcasp0_ahclkr   5       pru0.r30.3          P9.28	SPI1_CS0
  317 :                   : //                      6       pru0.r31.3
  318 :                   : //  B12 mcasp0_aclkr    5       pru0.r30.4          -
  319 :                   : //                      6       pru0.r31.4
  320 :                   : //  C13 mcasp0_fsr      5       pru0.r30.5          P9.27	GPIO3_19
  321 :                   : //                      6       pru0.r31.5
  322 :                   : //  D13 mcasp0_axr1     5       pru0.r30.6          -
  323 :                   : //                      6       pru0.r31.6
  324 :                   : //  A14 mcasp0_ahclkx   5       pru0.r30.7          P9.25	GPIO3_21
  325 :                   : //                      6       pru0.r31.7
  326 :                   : //  F17 mmc0_dat3       5       pru0.r30.8          -
  327 :                   : //                      6       pru0.r31.8
  328 :                   : //  F18 mmc0_dat2       5       pru0.r30.9          -
  329 :                   : //                      6       pru0.r31.9
  330 :                   : //  G15 mmc0_dat1       5       pru0.r30.10         -
  331 :                   : //                      6       pru0.r31.10
  332 :                   : //  G16 mmc0_dat0       5       pru0.r30.11         -
  333 :                   : //                      6       pru0.r31.11
  334 :                   : //  G17 mmc0_clk        5       pru0.r30.12         -
  335 :                   : //                      6       pru0.r31.12
  336 :                   : //  G18 mmc0_cmd        5       pru0.r30.13         -
  337 :                   : //                      6       pru0.r31.13
  338 :                   : //  T12 gpmc_ad12       6       pru0.r30.14         P8.12   GPIO1_12    
  339 :                   : //  V13 gpmc_ad14       6       pru0.r31.14         P8.16	GPIO1_14
  340 :                   : //  R12 gpmc_ad13       6       pru0.r30.15         P8.11   GPIO1_13    
  341 :                   : //  U13 gpmc_ad15       6       pru0.r31.15         P8.15	GPIO1_15
  342 :                   : //  D14 xdma_event_intr1 5      pru0.r31.16	P9.41	CLKOUT2
  343 :                   : //  D15 uart1_txd       6       pru0.r31.16	P9.24	UART1_TXD
  344 :                   : //  
  345 :                   : //  R1  lcd_data0       5       pru1.r30.0          P8.45   GPIO2_6     J3
  346 :                   : //                      6       pru1.r31.0
  347 :                   : //  R2  lcd_data1       5       pru1.r30.1          P8.46   GPIO2_7     J2
  348 :                   : //                      6       pru1.r31.1
  349 :                   : //  R3  lcd_data2       5       pru1.r30.2          P8.43   GPIO2_8     X Step
  350 :                   : //                      6       pru1.r31.2
  351 :                   : //  R4  lcd_data3       5       pru1.r30.3          P8.44   GPIO2_9     X Dir
  352 :                   : //                      6       pru1.r31.3
  353 :                   : //  T1  lcd_data4       5       pru1.r30.4          P8.41   GPIO2_10    X Enable    
  354 :                   : //                      6       pru1.r31.4
  355 :                   : //  T2  lcd_data5       5       pru1.r30.5          P8.42   GPIO2_11    Y Step
  356 :                   : //                      6       pru1.r31.5
  357 :                   : //  T3  lcd_data6       5       pru1.r30.6          P8.39   GPIO2_12    Y Dir
  358 :                   : //                      6       pru1.r31.6
  359 :                   : //  T4  lcd_data7       5       pru1.r30.7          P8.40   GPIO2_13    Y Enable
  360 :                   : //                      6       pru1.r31.7
  361 :                   : //  U8  lcd_vsync       5       pru1.r30.8          P8.27   GPIO2_22    Z Step
  362 :                   : //                      6       pru1.r31.8
  363 :                   : //  R5  lcd_hsync       5       pru1.r30.9          P8.29   GPIO2_23    Z Dir
  364 :                   : //                      6       pru1.r31.9
  365 :                   : //  V5  lcd_pclk        5       pru1.r30.10         P8.28   GPIO2_24    Z Enable
  366 :                   : //                      6       pru1.r31.10
  367 :                   : //  R6  lcd_ac_bias_en  5       pru1.r30.11         P8.30   GPIO2_25    E Step
  368 :                   : //                      6       pru1.r31.11
  369 :                   : //  U9  gpmc_csn1       5       pru1.r30.12         P8.21   GPIO1_30    E Dir
  370 :                   : //                      6       pru1.r31.12
  371 :                   : //  V9  gpmc_csn2       5       pru1.r30.13         P8.20   GPIO1_31    E Enable
  372 :                   : //                      6       pru1.r31.13
  373 :                   : //  E15 uart0_rxd       5       pru1.r30.14         -
  374 :                   : //                      6       pru1.r31.14
  375 :                   : //  E16 uart0_txd       5       pru1.r30.15         -
  376 :                   : //                      6       pru1.r31.15
  377 :                   : //  A15 xdma_event_intr0 5      pru1.r31.16         -
  378 :                   : //  D16 uart1_rxd       6       pru1.r31.16	P9.26	UART1_RXD
  379 :                   : //
  380 :                   : //  U3  lcd_data10      -       -                   P8.36   UART3_CTSN  J4
  381 :                   : //
  382 :                   : //      ecap0_in_pwm0_out 3     ecap0_ecap_capin_apwm_o
  383 :                   : //                  
  384 :                   : 
  385 :                   : 
  386 :                   : 
  387 :                   : 
  388 :                   : //                          BeagleBone          AM3359ZCZ           Mux                
  389 :                   : //  Replicape   BeBoPr      Pin     Name        Pin Name            Value   PRU I/O Pin
  390 :                   : //  ----------------------------------------------------------------------------------
  391 :                   : //  
  392 :                   : //                          P8.1    GND
  393 :                   : //                          P8.2    GND
  394 :                   : //  E2_Step     Enable      P8.3    GPIO1_6     R9  gpmc_ad6
  395 :                   : //  E1_Dir                  P8.4    GPIO1_7     T9  gpmc_ad7
  396 :                   : //              Enable_n    P8.5    GPIO1_2     R8  gpmc_ad2
  397 :                   : //                          P8.6    GPIO1_3     T8  gpmc_ad3
  398 :                   : //                          P8.7    TIMER4      R7  gpmc_advn_ale
  399 :                   : //  E2_Fault                P8.8    TIMER7      T7  gpmc_oen_ren
  400 :                   : //                          P8.9    TIMER5      T6  gpmc_be0n_cle
  401 :                   : //  X_Fault                 P8.10   TIMER6      U6  gpmc_wen
  402 :                   : //  X_Dir                   P8.11   GPIO1_13    R12 gpmc_ad13       6       pru0.r30.15         
  403 :                   : //  X_Step                  P8.12   GPIO1_12    T12 gpmc_ad12       6       pru0.r30.14
  404 :                   : //  E1_Heat                 P8.13   EHRPWM2B    T10 gpmc_ad9
  405 :                   : //  Y_Stop_1                P8.14   GPIO0_26    T11 gpmc_ad10
  406 :                   : //  Y_Fault                 P8.15	GPIO1_15    U13 gpmc_ad15       6       pru0.r31.15         
  407 :                   : //  E2_Step                 P8.16	GPIO1_14    V13 gpmc_ad14       6       pru0.r31.14         
  408 :                   : //  Z_Fault                 P8.17   GPIO0_27    U12 gpmc_ad11
  409 :                   : //  E1_Fault                P8.18   GPIO2_1     V12 gpmc_clk_mux0
  410 :                   : //  E2_Heat                 P8.19   EHRPWM2A    U10 gpmc_ad8
  411 :                   : //  Y_Step      E_Ena       P8.20   GPIO1_31    V9  gpmc_csn2       5       pru1.r30.13
  412 :                   : //  Y_Dir       E_Dir       P8.21   GPIO1_30    U9  gpmc_csn1       5       pru1.r30.12
  413 :                   : //  X_Stop_1                P8.22   GPIO1_5     V8  gpmc_ad5
  414 :                   : //                          P8.23   GPIO1_4     U8  gpmc_ad4
  415 :                   : //  Z_Step                  P8.24   GPIO1_1     V7  gpmc_ad1
  416 :                   : //                          P8.25   GPIO1_0     U7  gpmc_ad0
  417 :                   : //  Z_Stop_1                P8.26   GPIO1_29    V6  gpmc_csn0
  418 :                   : //              Z_Step      P8.27   GPIO2_22    U5  lcd_vsync       5       pru1.r30.8 
  419 :                   : //              Z_Ena       P8.28   GPIO2_24    V5  lcd_pclk        5       pru1.r30.10
  420 :                   : //              Z_Dir       P8.29   GPIO2_23    R5  lcd_hsync       5       pru1.r30.9 
  421 :                   : //              E_Step      P8.30   GPIO2_25    R6  lcd_ac_bias_en  5       pru1.r30.11
  422 :                   : //                          P8.31   UART5_CTSN  V4  lcd_data14
  423 :                   : //                          P8.32   UART5_RTSN  T5  lcd_data15
  424 :                   : //                          P8.33   UART4_RTSN  V3  lcd_data13
  425 :                   : //                          P8.34   UART3_RTSN  U4  lcd_data11
  426 :                   : //                          P8.35   UART4_CTSN  V2  lcd_data12
  427 :                   : //              J4          P8.36   UART3_CTSN  U3  lcd_data10
  428 :                   : //                          P8.37   UART5_TXD   U1  lcd_data8
  429 :                   : //                          P8.38   UART5_RXD   U2  lcd_data9
  430 :                   : //              Y_Dir       P8.39   GPIO2_12    T3  lcd_data6       5       pru1.r30.6 
  431 :                   : //              Y_Ena       P8.40   GPIO2_13    T4  lcd_data7       5       pru1.r30.7 
  432 :                   : //              X_Ena       P8.41   GPIO2_10    T1  lcd_data4       5       pru1.r30.4 
  433 :                   : //              Y_Step      P8.42   GPIO2_11    T2  lcd_data5       5       pru1.r30.5 
  434 :                   : //              X_Step      P8.43   GPIO2_8     R3  lcd_data2       5       pru1.r30.2 
  435 :                   : //              X_Dir       P8.44   GPIO2_9     R4  lcd_data3       5       pru1.r30.3 
  436 :                   : //              J3          P8.45   GPIO2_6     R1  lcd_data0       5       pru1.r30.0 
  437 :                   : //              J2          P8.46   GPIO2_7     R2  lcd_data1       5       pru1.r30.1 
  438 :                   : //  
  439 :                   : //                          P9.1    GND
  440 :                   : //                          P9.2    GND
  441 :                   : //                          P9.3    VDD_3V3EXP
  442 :                   : //                          P9.4    VDD_3V3EXP
  443 :                   : //                          P9.5    VDD_5V
  444 :                   : //                          P9.6    VDD_5V
  445 :                   : //                          P9.7    SYS_5V
  446 :                   : //                          P9.8    SYS_5V
  447 :                   : //                          P9.9    PWR_BUT
  448 :                   : //                          P9.10   SYS_RESETn  A10 RESET_OUT
  449 :                   : //                          P9.11   UART4_RXD   T17 gpmc_wait0
  450 :                   : //  Z_Stop_2                P9.12   GPIO1_28    U18 gpmc_be1n
  451 :                   : //  X_Stop_2                P9.13   UART4_TXD   U17 gpmc_wpn
  452 :                   : //                          P9.14   EHRPWM1A    U14 gpmc_a2
  453 :                   : //                          P9.15   GPIO1_16    R13 gpmc_a0
  454 :                   : //                          P9.16   EHRPWM1B    T14 gpmc_a3
  455 :                   : //  Y_Stop_2                P9.17   I2C1_SCL    A16 spi0_cs0
  456 :                   : //                          P9.18   I2C1_SDA    B16 spi0_d1
  457 :                   : //                          P9.19   I2C2_SCL    D17 uart1_rtsn
  458 :                   : //                          P9.20   I2C2_SDA    D18 uart1_ctsn
  459 :                   : //                          P9.21   UART2_TXD   B17 spi0_d0
  460 :                   : //  HBP_Heat                P9.22   UART2_RXD   A17 spi0_sclk
  461 :                   : //                          P9.23   GPIO1_17    V14 gpmc_a1
  462 :                   : //                          P9.24   UART1_TXD   D15 uart1_txd
  463 :                   : //  E1_Step                 P9.25   GPIO3_21    A14 mcasp0_ahclkx
  464 :                   : //                          P9.26   UART1_RXD   D16 uart1_rxd
  465 :                   : //                          P9.27   GPIO3_19    C13 mcasp0_fsr
  466 :                   : //                          P9.28   SPI1_CS0    C12 mcasp0_ahclkr
  467 :                   : //                          P9.29   SPI1_D0     B13 mcasp0_fsx
  468 :                   : //                          P9.30   SPI1_D1     D12 mcasp0_axr0
  469 :                   : //                          P9.31   SPI1_SCLK   A13 mcasp0_aclkx
  470 :                   : //                          P9.32   VDD_ADC
  471 :                   : //  E2_Temp                 P9.33   AIN4        C8  AIN4
  472 :                   : //                          P9.34   GNDA_ADC
  473 :                   : //  E1_Temp                 P9.35   AIN6        A8  AIN6
  474 :                   : //  HBP_Temp    Temp2 J8    P9.36   AIN5        B8  AIN5
  475 :                   : //                          P9.37   AIN2        B7  AIN2
  476 :                   : //              Temp1 J7    P9.38   AIN3        A7  AIN3
  477 :                   : //                          P9.39   AIN0        B6  AIN0
  478 :                   : //              Temp0 J6    P9.40   AIN1        C7  AIN1
  479 :                   : //                          P9.41   CLKOUT2     D14 xdma_event_intr1
  480 :                   : //                          bbb*    GPIO3_20    D13 mcasp0_axr1
  481 :                   : //                          P9.42   GPIO0_7     C18 eCAP0_in_PWM0_out
  482 :                   : //                          bbb*    GPIO3_18    B12 Mcasp0_aclkrp
  483 :                   : //                          P9.43   GND             
  484 :                   : //                          P9.44   GND             
  485 :                   : //                          P9.45   GND
  486 :                   : //                          P9.46   GND             
  487 :                   : //
  488 :                   : //                          bbb* = Only present on BeagleBone Black
  489 :                   : 

Source File 2 : 'pru.h' (No Ouput Generated)

    1 :                   : #ifndef _pru_H_
    2 :                   : #define _pru_H_
    3 :                   : 
    4 :                   : // this file is from https://github.com/millerap/AM335x_PRU_BeagleBone/blob/master/pwm_sin/bin/pru.hp
    5 :                   : // the PASM macros have been factored out into pru_macros.hp so
    6 :                   : // this file can be used both from C and PASM
    7 :                   : 
    8 :                   : // ***************************************
    9 :                   : // * Global Macro definitions *
   10 :                   : // ***************************************
   11 :                   : 
   12 :                   : // Refer to this mapping in the file - \prussdrv\include\pruss_intc_mapping.h
   13 :                   : #define PRU0_PRU1_INTERRUPT 17
   14 :                   : #define PRU1_PRU0_INTERRUPT 18
   15 :                   : #define PRU0_ARM_INTERRUPT 19
   16 :                   : #define PRU1_ARM_INTERRUPT 20
   17 :                   : #define ARM_PRU0_INTERRUPT 21
   18 :                   : #define ARM_PRU1_INTERRUPT 22
   19 :                   : 
   20 :                   : #define CONST_PRUSSINTC C0
   21 :                   : #define CONST_PRUCFG C4
   22 :                   : #define CONST_PRUDRAM C24
   23 :                   : #define CONST_PRUDRAM_REMOTE C25
   24 :                   : #define CONST_IEP C26
   25 :                   : #define CONST_PRUSHAREDRAM C28
   26 :                   : #define CONST_L3RAM C30
   27 :                   : #define CONST_DDR C31
   28 :                   : 
   29 :                   : #define PRU_ICSS_BASE 0x4a300000
   30 :                   : #define CTRL_CONTROL 0x22000
   31 :                   : #define CTRL_STATUS 0x22004
   32 :                   : #define CTRL_WAKEUP_EN 0x22008
   33 :                   : #define CTRL_CYCLE 0x2200c
   34 :                   : #define CTRL_STALL 0x22010
   35 :                   : 
   36 :                   : // Address for the Constant table Programmable Pointer Register 0(CTPPR_0)
   37 :                   : #define CTBIR_0 0x22020
   38 :                   : // Address for the Constant table Programmable Pointer Register 0(CTPPR_0)
   39 :                   : #define CTBIR_1 0x22024
   40 :                   : // Address for the Constant table Programmable Pointer Register 0(CTPPR_0)
   41 :                   : #define CTPPR_0 0x22028
   42 :                   : // Address for the Constant table Programmable Pointer Register 1(CTPPR_1)
   43 :                   : #define CTPPR_1 0x2202C
   44 :                   : 
   45 :                   : #define GER_OFFSET 0x10
   46 :                   : #define HIESR_OFFSET 0x34
   47 :                   : #define SICR_OFFSET 0x24
   48 :                   : #define EISR_OFFSET 0x28
   49 :                   : 
   50 :                   : #define INTC_CHNMAP_REGS_OFFSET 0x0400
   51 :                   : #define INTC_HOSTMAP_REGS_OFFSET 0x0800
   52 :                   : #define INTC_HOSTINTPRIO_REGS_OFFSET 0x0900
   53 :                   : #define INTC_HOSTNEST_REGS_OFFSET 0x1100
   54 :                   : 
   55 :                   : // Bit 5: 1 - Input, 0 - Output
   56 :                   : // Bit 4: 1 - Pull up, 0 - Pull down
   57 :                   : // Bit 3: 1 - Pull disabled, 0 - Pull enabled
   58 :                   : // Bit 2 \_
   59 :                   : // Bit 1 |- Mode
   60 :                   : // Bit 0 /
   61 :                   : 
   62 :                   : // MODE0 - Mux Mode 0
   63 :                   : // MODE1 - Mux Mode 1
   64 :                   : // MODE2 - Mux Mode 2
   65 :                   : // MODE3 - Mux Mode 3
   66 :                   : // MODE4 - Mux Mode 4
   67 :                   : // MODE5 - Mux Mode 5
   68 :                   : // MODE6 - Mux Mode 6
   69 :                   : // MODE7 - Mux Mode 7
   70 :                   : // IDIS - Receiver disabled
   71 :                   : // IEN - Receiver enabled
   72 :                   : // PD - Internal pull-down
   73 :                   : // PU - Internal pull-up
   74 :                   : // OFF - Internal pull disabled
   75 :                   : 
   76 :                   : #define MODE0 0
   77 :                   : #define MODE1 1
   78 :                   : #define MODE2 2
   79 :                   : #define MODE3 3
   80 :                   : #define MODE4 4
   81 :                   : #define MODE5 5
   82 :                   : #define MODE6 6
   83 :                   : #define MODE7 7
   84 :                   : #define IDIS (0 << 5)
   85 :                   : #define IEN (1 << 5)
   86 :                   : #define PD (0 << 3)
   87 :                   : #define PU (2 << 3)
   88 :                   : #define OFF (1 << 3)
   89 :                   : 
   90 :                   : // To get the physical address the offset has
   91 :                   : // to be added to AM335X_CTRL_BASE
   92 :                   : 
   93 :                   : #define CONTROL_PADCONF_GPMC_AD0                  0x0800
   94 :                   : #define CONTROL_PADCONF_GPMC_AD1                  0x0804
   95 :                   : #define CONTROL_PADCONF_GPMC_AD2                  0x0808
   96 :                   : #define CONTROL_PADCONF_GPMC_AD3                  0x080C
   97 :                   : #define CONTROL_PADCONF_GPMC_AD4                  0x0810
   98 :                   : #define CONTROL_PADCONF_GPMC_AD5                  0x0814
   99 :                   : #define CONTROL_PADCONF_GPMC_AD6                  0x0818
  100 :                   : #define CONTROL_PADCONF_GPMC_AD7                  0x081C
  101 :                   : #define CONTROL_PADCONF_GPMC_AD8                  0x0820
  102 :                   : #define CONTROL_PADCONF_GPMC_AD9                  0x0824
  103 :                   : #define CONTROL_PADCONF_GPMC_AD10                 0x0828
  104 :                   : #define CONTROL_PADCONF_GPMC_AD11                 0x082C
  105 :                   : #define CONTROL_PADCONF_GPMC_AD12                 0x0830
  106 :                   : #define CONTROL_PADCONF_GPMC_AD13                 0x0834
  107 :                   : #define CONTROL_PADCONF_GPMC_AD14                 0x0838
  108 :                   : #define CONTROL_PADCONF_GPMC_AD15                 0x083C
  109 :                   : #define CONTROL_PADCONF_GPMC_A0                   0x0840
  110 :                   : #define CONTROL_PADCONF_GPMC_A1                   0x0844
  111 :                   : #define CONTROL_PADCONF_GPMC_A2                   0x0848
  112 :                   : #define CONTROL_PADCONF_GPMC_A3                   0x084C
  113 :                   : #define CONTROL_PADCONF_GPMC_A4                   0x0850
  114 :                   : #define CONTROL_PADCONF_GPMC_A5                   0x0854
  115 :                   : #define CONTROL_PADCONF_GPMC_A6                   0x0858
  116 :                   : #define CONTROL_PADCONF_GPMC_A7                   0x085C
  117 :                   : #define CONTROL_PADCONF_GPMC_A8                   0x0860
  118 :                   : #define CONTROL_PADCONF_GPMC_A9                   0x0864
  119 :                   : #define CONTROL_PADCONF_GPMC_A10                  0x0868
  120 :                   : #define CONTROL_PADCONF_GPMC_A11                  0x086C
  121 :                   : #define CONTROL_PADCONF_GPMC_WAIT0                0x0870
  122 :                   : #define CONTROL_PADCONF_GPMC_WPN                  0x0874
  123 :                   : #define CONTROL_PADCONF_GPMC_BEN1                 0x0878
  124 :                   : #define CONTROL_PADCONF_GPMC_CSN0                 0x087C
  125 :                   : #define CONTROL_PADCONF_GPMC_CSN1                 0x0880
  126 :                   : #define CONTROL_PADCONF_GPMC_CSN2                 0x0884
  127 :                   : #define CONTROL_PADCONF_GPMC_CSN3                 0x0888
  128 :                   : #define CONTROL_PADCONF_GPMC_CLK                  0x088C
  129 :                   : #define CONTROL_PADCONF_GPMC_ADVN_ALE             0x0890
  130 :                   : #define CONTROL_PADCONF_GPMC_OEN_REN              0x0894
  131 :                   : #define CONTROL_PADCONF_GPMC_WEN                  0x0898
  132 :                   : #define CONTROL_PADCONF_GPMC_BEN0_CLE             0x089C
  133 :                   : #define CONTROL_PADCONF_LCD_DATA0                 0x08A0
  134 :                   : #define CONTROL_PADCONF_LCD_DATA1                 0x08A4
  135 :                   : #define CONTROL_PADCONF_LCD_DATA2                 0x08A8
  136 :                   : #define CONTROL_PADCONF_LCD_DATA3                 0x08AC
  137 :                   : #define CONTROL_PADCONF_LCD_DATA4                 0x08B0
  138 :                   : #define CONTROL_PADCONF_LCD_DATA5                 0x08B4
  139 :                   : #define CONTROL_PADCONF_LCD_DATA6                 0x08B8
  140 :                   : #define CONTROL_PADCONF_LCD_DATA7                 0x08BC
  141 :                   : #define CONTROL_PADCONF_LCD_DATA8                 0x08C0
  142 :                   : #define CONTROL_PADCONF_LCD_DATA9                 0x08C4
  143 :                   : #define CONTROL_PADCONF_LCD_DATA10                0x08C8
  144 :                   : #define CONTROL_PADCONF_LCD_DATA11                0x08CC
  145 :                   : #define CONTROL_PADCONF_LCD_DATA12                0x08D0
  146 :                   : #define CONTROL_PADCONF_LCD_DATA13                0x08D4
  147 :                   : #define CONTROL_PADCONF_LCD_DATA14                0x08D8
  148 :                   : #define CONTROL_PADCONF_LCD_DATA15                0x08DC
  149 :                   : #define CONTROL_PADCONF_LCD_VSYNC                 0x08E0
  150 :                   : #define CONTROL_PADCONF_LCD_HSYNC                 0x08E4
  151 :                   : #define CONTROL_PADCONF_LCD_PCLK                  0x08E8
  152 :                   : #define CONTROL_PADCONF_LCD_AC_BIAS_EN            0x08EC
  153 :                   : #define CONTROL_PADCONF_MMC0_DAT3                 0x08F0
  154 :                   : #define CONTROL_PADCONF_MMC0_DAT2                 0x08F4
  155 :                   : #define CONTROL_PADCONF_MMC0_DAT1                 0x08F8
  156 :                   : #define CONTROL_PADCONF_MMC0_DAT0                 0x08FC
  157 :                   : #define CONTROL_PADCONF_MMC0_CLK                  0x0900
  158 :                   : #define CONTROL_PADCONF_MMC0_CMD                  0x0904
  159 :                   : #define CONTROL_PADCONF_MII1_COL                  0x0908
  160 :                   : #define CONTROL_PADCONF_MII1_CRS                  0x090C
  161 :                   : #define CONTROL_PADCONF_MII1_RX_ER                0x0910
  162 :                   : #define CONTROL_PADCONF_MII1_TX_EN                0x0914
  163 :                   : #define CONTROL_PADCONF_MII1_RX_DV                0x0918
  164 :                   : #define CONTROL_PADCONF_MII1_TXD3                 0x091C
  165 :                   : #define CONTROL_PADCONF_MII1_TXD2                 0x0920
  166 :                   : #define CONTROL_PADCONF_MII1_TXD1                 0x0924
  167 :                   : #define CONTROL_PADCONF_MII1_TXD0                 0x0928
  168 :                   : #define CONTROL_PADCONF_MII1_TX_CLK               0x092C
  169 :                   : #define CONTROL_PADCONF_MII1_RX_CLK               0x0930
  170 :                   : #define CONTROL_PADCONF_MII1_RXD3                 0x0934
  171 :                   : #define CONTROL_PADCONF_MII1_RXD2                 0x0938
  172 :                   : #define CONTROL_PADCONF_MII1_RXD1                 0x093C
  173 :                   : #define CONTROL_PADCONF_MII1_RXD0                 0x0940
  174 :                   : #define CONTROL_PADCONF_RMII1_REF_CLK             0x0944
  175 :                   : #define CONTROL_PADCONF_MDIO                      0x0948
  176 :                   : #define CONTROL_PADCONF_MDC                       0x094C
  177 :                   : #define CONTROL_PADCONF_SPI0_SCLK                 0x0950
  178 :                   : #define CONTROL_PADCONF_SPI0_D0                   0x0954
  179 :                   : #define CONTROL_PADCONF_SPI0_D1                   0x0958
  180 :                   : #define CONTROL_PADCONF_SPI0_CS0                  0x095C
  181 :                   : #define CONTROL_PADCONF_SPI0_CS1                  0x0960
  182 :                   : #define CONTROL_PADCONF_ECAP0_IN_PWM0_OUT         0x0964
  183 :                   : #define CONTROL_PADCONF_UART0_CTSN                0x0968
  184 :                   : #define CONTROL_PADCONF_UART0_RTSN                0x096C
  185 :                   : #define CONTROL_PADCONF_UART0_RXD                 0x0970
  186 :                   : #define CONTROL_PADCONF_UART0_TXD                 0x0974
  187 :                   : #define CONTROL_PADCONF_UART1_CTSN                0x0978
  188 :                   : #define CONTROL_PADCONF_UART1_RTSN                0x097C
  189 :                   : #define CONTROL_PADCONF_UART1_RXD                 0x0980
  190 :                   : #define CONTROL_PADCONF_UART1_TXD                 0x0984
  191 :                   : #define CONTROL_PADCONF_I2C0_SDA                  0x0988
  192 :                   : #define CONTROL_PADCONF_I2C0_SCL                  0x098C
  193 :                   : #define CONTROL_PADCONF_MCASP0_ACLKX              0x0990
  194 :                   : #define CONTROL_PADCONF_MCASP0_FSX                0x0994
  195 :                   : #define CONTROL_PADCONF_MCASP0_AXR0               0x0998
  196 :                   : #define CONTROL_PADCONF_MCASP0_AHCLKR             0x099C
  197 :                   : #define CONTROL_PADCONF_MCASP0_ACLKR              0x09A0
  198 :                   : #define CONTROL_PADCONF_MCASP0_FSR                0x09A4
  199 :                   : #define CONTROL_PADCONF_MCASP0_AXR1               0x09A8
  200 :                   : #define CONTROL_PADCONF_MCASP0_AHCLKX             0x09AC
  201 :                   : #define CONTROL_PADCONF_XDMA_EVENT_INTR0          0x09B0
  202 :                   : #define CONTROL_PADCONF_XDMA_EVENT_INTR1          0x09B4
  203 :                   : #define CONTROL_PADCONF_WARMRSTN                  0x09B8
  204 :                   : #define CONTROL_PADCONF_PWRONRSTN                 0x09BC
  205 :                   : #define CONTROL_PADCONF_EXTINTN                   0x09C0
  206 :                   : #define CONTROL_PADCONF_XTALIN                    0x09C4
  207 :                   : #define CONTROL_PADCONF_XTALOUT                   0x09C8
  208 :                   : #define CONTROL_PADCONF_TMS                       0x09D0
  209 :                   : #define CONTROL_PADCONF_TDI                       0x09D4
  210 :                   : #define CONTROL_PADCONF_TDO                       0x09D8
  211 :                   : #define CONTROL_PADCONF_TCK                       0x09DC
  212 :                   : #define CONTROL_PADCONF_TRSTN                     0x09E0
  213 :                   : #define CONTROL_PADCONF_EMU0                      0x09E4
  214 :                   : #define CONTROL_PADCONF_EMU1                      0x09E8
  215 :                   : #define CONTROL_PADCONF_RTC_XTALIN                0x09EC
  216 :                   : #define CONTROL_PADCONF_RTC_XTALOUT               0x09F0
  217 :                   : #define CONTROL_PADCONF_RTC_PWRONRSTN             0x09F8
  218 :                   : #define CONTROL_PADCONF_PMIC_POWER_EN             0x09FC
  219 :                   : #define CONTROL_PADCONF_EXT_WAKEUP                0x0A00
  220 :                   : #define CONTROL_PADCONF_RTC_KALDO_ENN             0x0A04
  221 :                   : #define CONTROL_PADCONF_USB0_DM                   0x0A08
  222 :                   : #define CONTROL_PADCONF_USB0_DP                   0x0A0C
  223 :                   : #define CONTROL_PADCONF_USB0_CE                   0x0A10
  224 :                   : #define CONTROL_PADCONF_USB0_ID                   0x0A14
  225 :                   : #define CONTROL_PADCONF_USB0_VBUS                 0x0A18
  226 :                   : #define CONTROL_PADCONF_USB0_DRVVBUS              0x0A1C
  227 :                   : #define CONTROL_PADCONF_USB1_DM                   0x0A20
  228 :                   : #define CONTROL_PADCONF_USB1_DP                   0x0A24
  229 :                   : #define CONTROL_PADCONF_USB1_CE                   0x0A28
  230 :                   : #define CONTROL_PADCONF_USB1_ID                   0x0A2C
  231 :                   : #define CONTROL_PADCONF_USB1_VBUS                 0x0A30
  232 :                   : #define CONTROL_PADCONF_USB1_DRVVBUS              0x0A34
  233 :                   : #define CONTROL_PADCONF_DDR_RESETN                0x0A38
  234 :                   : #define CONTROL_PADCONF_DDR_CSN0                  0x0A3C
  235 :                   : #define CONTROL_PADCONF_DDR_CKE                   0x0A40
  236 :                   : #define CONTROL_PADCONF_DDR_CK                    0x0A44
  237 :                   : #define CONTROL_PADCONF_DDR_CKN                   0x0A48
  238 :                   : #define CONTROL_PADCONF_DDR_CASN                  0x0A4C
  239 :                   : #define CONTROL_PADCONF_DDR_RASN                  0x0A50
  240 :                   : #define CONTROL_PADCONF_DDR_WEN                   0x0A54
  241 :                   : #define CONTROL_PADCONF_DDR_BA0                   0x0A58
  242 :                   : #define CONTROL_PADCONF_DDR_BA1                   0x0A5C
  243 :                   : #define CONTROL_PADCONF_DDR_BA2                   0x0A60
  244 :                   : #define CONTROL_PADCONF_DDR_A0                    0x0A64
  245 :                   : #define CONTROL_PADCONF_DDR_A1                    0x0A68
  246 :                   : #define CONTROL_PADCONF_DDR_A2                    0x0A6C
  247 :                   : #define CONTROL_PADCONF_DDR_A3                    0x0A70
  248 :                   : #define CONTROL_PADCONF_DDR_A4                    0x0A74
  249 :                   : #define CONTROL_PADCONF_DDR_A5                    0x0A78
  250 :                   : #define CONTROL_PADCONF_DDR_A6                    0x0A7C
  251 :                   : #define CONTROL_PADCONF_DDR_A7                    0x0A80
  252 :                   : #define CONTROL_PADCONF_DDR_A8                    0x0A84
  253 :                   : #define CONTROL_PADCONF_DDR_A9                    0x0A88
  254 :                   : #define CONTROL_PADCONF_DDR_A10                   0x0A8C
  255 :                   : #define CONTROL_PADCONF_DDR_A11                   0x0A90
  256 :                   : #define CONTROL_PADCONF_DDR_A12                   0x0A94
  257 :                   : #define CONTROL_PADCONF_DDR_A13                   0x0A98
  258 :                   : #define CONTROL_PADCONF_DDR_A14                   0x0A9C
  259 :                   : #define CONTROL_PADCONF_DDR_A15                   0x0AA0
  260 :                   : #define CONTROL_PADCONF_DDR_ODT                   0x0AA4
  261 :                   : #define CONTROL_PADCONF_DDR_D0                    0x0AA8
  262 :                   : #define CONTROL_PADCONF_DDR_D1                    0x0AAC
  263 :                   : #define CONTROL_PADCONF_DDR_D2                    0x0AB0
  264 :                   : #define CONTROL_PADCONF_DDR_D3                    0x0AB4
  265 :                   : #define CONTROL_PADCONF_DDR_D4                    0x0AB8
  266 :                   : #define CONTROL_PADCONF_DDR_D5                    0x0ABC
  267 :                   : #define CONTROL_PADCONF_DDR_D6                    0x0AC0
  268 :                   : #define CONTROL_PADCONF_DDR_D7                    0x0AC4
  269 :                   : #define CONTROL_PADCONF_DDR_D8                    0x0AC8
  270 :                   : #define CONTROL_PADCONF_DDR_D9                    0x0ACC
  271 :                   : #define CONTROL_PADCONF_DDR_D10                   0x0AD0
  272 :                   : #define CONTROL_PADCONF_DDR_D11                   0x0AD4
  273 :                   : #define CONTROL_PADCONF_DDR_D12                   0x0AD8
  274 :                   : #define CONTROL_PADCONF_DDR_D13                   0x0ADC
  275 :                   : #define CONTROL_PADCONF_DDR_D14                   0x0AE0
  276 :                   : #define CONTROL_PADCONF_DDR_D15                   0x0AE4
  277 :                   : #define CONTROL_PADCONF_DDR_DQM0                  0x0AE8
  278 :                   : #define CONTROL_PADCONF_DDR_DQM1                  0x0AEC
  279 :                   : #define CONTROL_PADCONF_DDR_DQS0                  0x0AF0
  280 :                   : #define CONTROL_PADCONF_DDR_DQSN0                 0x0AF4
  281 :                   : #define CONTROL_PADCONF_DDR_DQS1                  0x0AF8
  282 :                   : #define CONTROL_PADCONF_DDR_DQSN1                 0x0AFC
  283 :                   : #define CONTROL_PADCONF_DDR_VREF                  0x0B00
  284 :                   : #define CONTROL_PADCONF_DDR_VTP                   0x0B04
  285 :                   : #define CONTROL_PADCONF_AIN7                      0x0B10
  286 :                   : #define CONTROL_PADCONF_AIN6                      0x0B14
  287 :                   : #define CONTROL_PADCONF_AIN5                      0x0B18
  288 :                   : #define CONTROL_PADCONF_AIN4                      0x0B1C
  289 :                   : #define CONTROL_PADCONF_AIN3                      0x0B20
  290 :                   : #define CONTROL_PADCONF_AIN2                      0x0B24
  291 :                   : #define CONTROL_PADCONF_AIN1                      0x0B28
  292 :                   : #define CONTROL_PADCONF_AIN0                      0x0B2C
  293 :                   : #define CONTROL_PADCONF_VREFP                     0x0B30
  294 :                   : #define CONTROL_PADCONF_VREFN                     0x0B34
  295 :                   : 
  296 :                   : #define AM335X_CTRL_BASE 0x44E10000
  297 :                   : 
  298 :                   : 
  299 :                   : #define GPIO0 0x44e07000
  300 :                   : #define GPIO1 0x4804c000
  301 :                   : #define GPIO2 0x481ac000
  302 :                   : #define GPIO3 0x481ae000
  303 :                   : 
  304 :                   : #define GPIO_REVISION 0x0
  305 :                   : #define GPIO_SYSCONFIG 0x10
  306 :                   : #define GPIO_IRQSTATUS_RAW_0 0x24
  307 :                   : #define GPIO_IRQSTATUS_RAW_1 0x28
  308 :                   : #define GPIO_IRQSTATUS_0 0x2C
  309 :                   : #define GPIO_IRQSTATUS_1 0x30
  310 :                   : #define GPIO_IRQSTATUS_SET_0 0x34
  311 :                   : #define GPIO_IRQSTATUS_SET_1 0x38
  312 :                   : #define GPIO_IRQSTATUS_CLR_0 0x3C
  313 :                   : #define GPIO_IRQSTATUS_CLR_1 0x40
  314 :                   : #define GPIO_IRQWAKEN_0 0x44
  315 :                   : #define GPIO_IRQWAKEN_1 0x48
  316 :                   : #define GPIO_SYSSTATUS 0x114
  317 :                   : #define GPIO_CTRL 0x130
  318 :                   : #define GPIO_OE 0x134
  319 :                   : #define GPIO_DATAIN 0x138
  320 :                   : #define GPIO_DATAOUT 0x13C
  321 :                   : #define GPIO_LEVELDETECT0 0x140
  322 :                   : #define GPIO_LEVELDETECT1 0x144
  323 :                   : #define GPIO_RISINGDETECT 0x148
  324 :                   : #define GPIO_FALLINGDETECT 0x14C
  325 :                   : #define GPIO_DEBOUNCENABLE 0x150
  326 :                   : #define GPIO_DEBOUNCINGTIME 0x154
  327 :                   : #define GPIO_CLEARDATAOUT 0x190
  328 :                   : #define GPIO_SETDATAOUT 0x194
  329 :                   : 
  330 :                   : 
  331 :                   : 
  332 :                   : 
  333 :                   : 
  334 :                   : #endif // _pru_H_
  335 :                   : 

Source File 3 : 'pru_tasks.h' (No Ouput Generated)

    1 :                   : //----------------------------------------------------------------------//
    2 :                   : // Description: pru_tasks.h                                             //
    3 :                   : // Header with definitions that MUST match between the PRU assembly     //
    4 :                   : // and the LinuxCNC HAL driver code.  In hopes of keeping these         //
    5 :                   : // definitions consistant, both versions are contained in this file,    //
    6 :                   : // separated by #ifdefs                                                 //
    7 :                   : //                                                                      //
    8 :                   : // Author(s): Charles Steinkuehler                                      //
    9 :                   : // License: GNU GPL Version 2.0 or (at your option) any later version.  //
   10 :                   : //                                                                      //
   11 :                   : // Major Changes:                                                       //
   12 :                   : // 2013-May    Charles Steinkuehler                                     //
   13 :                   : //             Initial version                                          //
   14 :                   : //----------------------------------------------------------------------//
   15 :                   : // This file is part of LinuxCNC HAL                                    //
   16 :                   : //                                                                      //
   17 :                   : // Copyright (C) 2012  Charles Steinkuehler                             //
   18 :                   : //                     <charles AT steinkuehler DOT net>                //
   19 :                   : //                                                                      //
   20 :                   : // This program is free software; you can redistribute it and/or        //
   21 :                   : // modify it under the terms of the GNU General Public License          //
   22 :                   : // as published by the Free Software Foundation; either version 2       //
   23 :                   : // of the License, or (at your option) any later version.               //
   24 :                   : //                                                                      //
   25 :                   : // This program is distributed in the hope that it will be useful,      //
   26 :                   : // but WITHOUT ANY WARRANTY; without even the implied warranty of       //
   27 :                   : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
   28 :                   : // GNU General Public License for more details.                         //
   29 :                   : //                                                                      //
   30 :                   : // You should have received a copy of the GNU General Public License    //
   31 :                   : // along with this program; if not, write to the Free Software          //
   32 :                   : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA        //
   33 :                   : // 02110-1301, USA.                                                     //
   34 :                   : //                                                                      //
   35 :                   : // THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR       //
   36 :                   : // ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE   //
   37 :                   : // TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of      //
   38 :                   : // harming persons must have provisions for completely removing power   //
   39 :                   : // from all motors, etc, before persons enter any danger area.  All     //
   40 :                   : // machinery must be designed to comply with local and national safety  //
   41 :                   : // codes, and the authors of this software can not, and do not, take    //
   42 :                   : // any responsibility for such compliance.                              //
   43 :                   : //                                                                      //
   44 :                   : // This code was written as part of the LinuxCNC project.  For more     //
   45 :                   : // information, go to www.linuxcnc.org.                                 //
   46 :                   : //----------------------------------------------------------------------//
   47 :                   : 
   48 :                   : // This file defines the task structures and static variables needed to
   49 :                   : // communicate between the HAL code running on the ARM and real time
   50 :                   : // code running on the PRU
   51 :                   : //
   52 :                   : // Pre-processor #ifdef stanzas are used to allow both PRU assembly and
   53 :                   : // C style typedefs to exist in the same file, since it is critical that
   54 :                   : // the data structures for both sides match exactly.
   55 :                   : //
   56 :                   : // The _hal_pru_generic_H_ define (from hal_pru_generic.h) is used to 
   57 :                   : // deteremine if we are assembling pru code or compiling C code.
   58 :                   : 
   59 :                   : //
   60 :                   : // Basic types used elsewhere
   61 :                   : //
   62 :                   : 
   63 :                   : #define PRU_DATA_START 0
   64 :                   : 
   65 :                   : #ifndef _hal_pru_generic_H_
   66 :                   :     // pru_addr_t
   67 :                   :     
   68 :                   :     // pru_task_mode_t
   69 :                   : 
   70 :                   : #else
   71 :                   :     typedef u32 pru_addr_t;
   72 :                   : 
   73 :                   :     // Insure these values match the JUMPTABLE in the pru assembly code!
   74 :                   :     typedef enum { 
   75 :                   :         eMODE_INVALID   = -1,
   76 :                   :         eMODE_NONE      = 0,
   77 :                   :         eMODE_WAIT      = 1,
   78 :                   :         eMODE_WRITE     = 2,    // Not implemented yet!
   79 :                   :         eMODE_READ      = 3,    // Not implemented yet!
   80 :                   :         eMODE_STEP_DIR  = 4,
   81 :                   :         eMODE_UP_DOWN   = 5,    // Not implemented yet!
   82 :                   :         eMODE_DELTA_SIG = 6,
   83 :                   :         eMODE_PWM       = 7
   84 :                   :     } pru_task_mode_t;
   85 :                   : #endif
   86 :                   : 
   87 :                   : //
   88 :                   : // Task header
   89 :                   : //
   90 :                   : 
   91 :                   : #ifndef _hal_pru_generic_H_
   92 :                   :     .struct task_header
   93 :                   :         .u8     mode
   94 :                   :         .u8     len
   95 :                   :         .u8     dataX
   96 :                   :         .u8     dataY
   97 :                   :         .u32    addr
   98 :                   :     .ends
   99 :                   : #else
  100 :                   :     typedef struct {
  101 :                   :         u8      mode;
  102 :                   :         u8      len;
  103 :                   :         u8      dataX;
  104 :                   :         u8      dataY;
  105 :                   :         u32     addr;
  106 :                   :     } PRU_task_hdr_t;
  107 :                   : 
  108 :                   :     typedef union {
  109 :                   :         u32     dword[2];
  110 :                   :         u16     word[4];
  111 :                   :         u8      byte[8];
  112 :                   :     } PRU_task_raw_t;
  113 :                   : 
  114 :                   :     typedef union {
  115 :                   :         PRU_task_raw_t raw;
  116 :                   :         PRU_task_hdr_t hdr;
  117 :                   :     } PRU_task_header_t;
  118 :                   : #endif
  119 :                   : 
  120 :                   : //
  121 :                   : // Static variables
  122 :                   : //
  123 :                   : 
  124 :                   : #ifndef _hal_pru_generic_H_
  125 :                   :     .struct pru_statics
  126 :                   :         .u8     mode
  127 :                   :         .u8     len
  128 :                   :         .u8     dataX
  129 :                   :         .u8     dataY
  130 :                   :         .u32    addr
  131 :                   :         .u32    period
  132 :                   :     .ends
  133 :                   : #else
  134 :                   :     typedef struct {
  135 :                   :         PRU_task_header_t task;
  136 :                   :         u32     period;
  137 :                   :     } PRU_statics_t;
  138 :                   : #endif
  139 :                   : 
  140 :                   : //
  141 :                   : // Task structures, one for each 'flavor'
  142 :                   : // The PRU versions do not include the task header, as the current task header
  143 :                   : // is a global variable in the PRU assembly code
  144 :                   : //
  145 :                   : 
  146 :                   : //
  147 :                   : // stepgen task
  148 :                   : //
  149 :                   : 
  150 :                   : #ifndef _hal_pru_generic_H_
  151 :                   :     .struct stepgen_state
  152 :                   :         .u32    Rate
  153 :                   :         .u16    Dly_step_high
  154 :                   :         .u16    Dly_dir_hold
  155 :                   :         .u16    Dly_step_low
  156 :                   :         .u16    Dly_dir_setup
  157 :                   :         .u32    Accum
  158 :                   :         .u32    Pos
  159 :                   :         .u16    T_Pulse
  160 :                   :         .u16    T_Dir
  161 :                   :         .u16    Reserved1
  162 :                   :         .u8     StepQ
  163 :                   :         .u8     RateQ
  164 :                   :     .ends
  165 :                   : #else
  166 :                   :     typedef struct  {
  167 :                   :         PRU_task_header_t task;
  168 :                   : 
  169 :                   :         s32     rate;
  170 :                   :         u16     steplen;
  171 :                   :         u16     dirhold;
  172 :                   :         u16     stepspace;
  173 :                   :         u16     dirsetup;
  174 :                   :         u32     accum;
  175 :                   :         u32     pos;
  176 :                   :         u32     reserved[2];
  177 :                   :     } PRU_task_stepdir_t;
  178 :                   : #endif
  179 :                   : 
  180 :                   : //
  181 :                   : // delta-sigma modulator task
  182 :                   : //
  183 :                   : 
  184 :                   : #ifndef _hal_pru_generic_H_
  185 :                   :     .struct delta_index
  186 :                   :         .u16    Offset
  187 :                   :         .u16    Reserved
  188 :                   :     .ends
  189 :                   : 
  190 :                   :     .struct delta_output
  191 :                   :         .u16    Value           // WARNING: Range is 14-bits: 0x0000 to 0x4000 inclusive!
  192 :                   :         .u8     Pin
  193 :                   :         .u8     Reserved
  194 :                   :         .u16    Integrate
  195 :                   :         .u16    Quantize
  196 :                   :     .ends
  197 :                   : 
  198 :                   :     .struct delta_state
  199 :                   :         .u32    Reserved
  200 :                   :     .ends
  201 :                   : #else
  202 :                   :     typedef struct {
  203 :                   :         u16     value;          // WARNING: Range is 14-bits: 0x0000 to 0x4000 inclusive!
  204 :                   :         u8      pin;
  205 :                   :         u8      reserved;
  206 :                   :         u32     state;
  207 :                   :     } PRU_delta_output_t;
  208 :                   : 
  209 :                   :     typedef struct {
  210 :                   :         PRU_task_header_t task;
  211 :                   : 
  212 :                   :         u32     reserved;
  213 :                   :     //  PRU_delta_output_t out[task.len];
  214 :                   :     } PRU_task_delta_t;
  215 :                   : #endif
  216 :                   : 
  217 :                   : //
  218 :                   : // pwmgen task
  219 :                   : //
  220 :                   : 
  221 :                   : #ifndef _hal_pru_generic_H_
  222 :                   :     .struct pwm_index
  223 :                   :         .u16    Offset
  224 :                   :         .u16    Reserved
  225 :                   :     .ends
  226 :                   : 
  227 :                   :     .struct pwm_output
  228 :                   :         .u16    Value
  229 :                   :         .u8     Pin
  230 :                   :         .u8     Reserved
  231 :                   :     .ends
  232 :                   : 
  233 :                   :     .struct pwm_state
  234 :                   :         .u16    Prescale
  235 :                   :         .u16    Period
  236 :                   :         .u16    T_Prescale
  237 :                   :         .u16    T_Period
  238 :                   :     .ends
  239 :                   : #else
  240 :                   :     typedef struct {
  241 :                   :         u16     value;
  242 :                   :         u8      pin;
  243 :                   :         u8      reserved;
  244 :                   :     } PRU_pwm_output_t;
  245 :                   : 
  246 :                   :     typedef struct {
  247 :                   :         PRU_task_header_t task;
  248 :                   : 
  249 :                   :         u16     prescale;
  250 :                   :         u16     period;
  251 :                   :         u32     reserved;
  252 :                   :     //  PRU_pwm_output_t out[task.len];
  253 :                   :     } PRU_task_pwm_t;
  254 :                   : #endif
  255 :                   : 
  256 :                   : //
  257 :                   : // wait task
  258 :                   : //
  259 :                   : 
  260 :                   : #ifndef _hal_pru_generic_H_
  261 :                   : 
  262 :                   : #else
  263 :                   :     typedef struct {
  264 :                   :         PRU_task_header_t task;
  265 :                   :     } PRU_task_wait_t;
  266 :                   : #endif
  267 :                   : 

Source File 4 : 'pru_wait.p' (18 Instructions Generated)

    1 :                   : //----------------------------------------------------------------------//
    2 :                   : // Description: pru.wait.p                                              //
    3 :                   : // PRU code implementing the wait task, delaying execution until the    //
    4 :                   : // next "timer tick" and updating the PRU and GPIO outputs              //
    5 :                   : //                                                                      //
    6 :                   : // Author(s): Charles Steinkuehler                                      //
    7 :                   : // License: GNU GPL Version 2.0 or (at your option) any later version.  //
    8 :                   : //                                                                      //
    9 :                   : // Major Changes:                                                       //
   10 :                   : // 2013-May    Charles Steinkuehler                                     //
   11 :                   : //             Split into several files                                 //
   12 :                   : //             Altered main loop to support a linked list of tasks      //
   13 :                   : //             Added support for GPIO pins in addition to PRU outputs   //
   14 :                   : // 2012-Dec-27 Charles Steinkuehler                                     //
   15 :                   : //             Initial version                                          //
   16 :                   : //----------------------------------------------------------------------//
   17 :                   : // This file is part of LinuxCNC HAL                                    //
   18 :                   : //                                                                      //
   19 :                   : // Copyright (C) 2013  Charles Steinkuehler                             //
   20 :                   : //                     <charles AT steinkuehler DOT net>                //
   21 :                   : //                                                                      //
   22 :                   : // This program is free software; you can redistribute it and/or        //
   23 :                   : // modify it under the terms of the GNU General Public License          //
   24 :                   : // as published by the Free Software Foundation; either version 2       //
   25 :                   : // of the License, or (at your option) any later version.               //
   26 :                   : //                                                                      //
   27 :                   : // This program is distributed in the hope that it will be useful,      //
   28 :                   : // but WITHOUT ANY WARRANTY; without even the implied warranty of       //
   29 :                   : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
   30 :                   : // GNU General Public License for more details.                         //
   31 :                   : //                                                                      //
   32 :                   : // You should have received a copy of the GNU General Public License    //
   33 :                   : // along with this program; if not, write to the Free Software          //
   34 :                   : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA        //
   35 :                   : // 02110-1301, USA.                                                     //
   36 :                   : //                                                                      //
   37 :                   : // THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR       //
   38 :                   : // ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE   //
   39 :                   : // TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of      //
   40 :                   : // harming persons must have provisions for completely removing power   //
   41 :                   : // from all motors, etc, before persons enter any danger area.  All     //
   42 :                   : // machinery must be designed to comply with local and national safety  //
   43 :                   : // codes, and the authors of this software can not, and do not, take    //
   44 :                   : // any responsibility for such compliance.                              //
   45 :                   : //                                                                      //
   46 :                   : // This code was written as part of the LinuxCNC project.  For more     //
   47 :                   : // information, go to www.linuxcnc.org.                                 //
   48 :                   : //----------------------------------------------------------------------//
   49 :                   : 
   50 :                   : MODE_WAIT:
   51 :                   : .enter WAIT_SCOPE
   52 :                   : 
   53 :                   : .struct wait_state
   54 :                   :     .u32    GPIO0_Clr_Addr
   55 :                   :     .u32    GPIO1_Clr_Addr
   56 :                   :     .u32    GPIO2_Clr_Addr
   57 :                   :     .u32    GPIO3_Clr_Addr
   58 :                   : .ends
   59 :                   : 
   60 :                   : .assign wait_state, GState.State_Reg0, *, State
   61 :                   : 
   62 :                   :     // FIXME:
   63 :                   :     // This scheme requires the GPIO addresses to be stored as local data
   64 :                   :     // in the wait task.  A better solution would be to use the Register
   65 :                   :     // Transfer instructions and pull the data from a scratchpad
   66 :                   : 
   67 :                   :     // Read channel state data
   68 :                   : //    LBBO    STATE_REG, GTask.addr, 8, SIZE(State)
   69 : 0x004d 0x2e850784 :     XIN     10, State, 16
   70 :                   : 
   71 :                   :     // Debugging:
   72 :                   :     // Task_DataY indicates we had a real-time error, or the timer tick
   73 :                   :     // occurred before we began waiting for it!
   74 :                   :     
   75 : 0x004e 0x91443a82 :     LBCO    r2, CONST_IEP, 0x44, 4      // Load CMP_STATUS register
   76 : 0x004f 0xc900e202 :     QBBC    BUSY_CHECK, r2, 0           // Check to see if timer has expired already
   77 : 0x0050 0x1f076c6c :     SET     GTask.dataY,7               // Set MSB if error
   78 :                   : 
   79 :                   :     // Debugging:
   80 :                   :     // Task_DataX is used to indicate we should set a busy bit when code
   81 :                   :     // begins executing after a timer tick, and clear it once all work
   82 :                   :     // is complete and we are waiting for the next timer tick
   83 :                   : BUSY_CHECK:
   84 : 0x0051 0xc9074c03 :     QBBC    WAITLOOP, GTask.dataX, 7        // If MSB is set, we should twiddle the busy bit
   85 : 0x0052 0x1c4cfefe :     CLR     r30, GTask.dataX                // Clear busy bit
   86 : 0x0053 0x1e4cf6f6 :     SET     GState.PRU_Out, GTask.dataX     // Set busy bit with all other outputs after we wait for a timer tick
   87 :                   : 
   88 :                   : WAITLOOP:
   89 :                   :     // Wait until the next timer tick...
   90 :                   :     // FIXME:
   91 :                   :     // Set up interrupt routing for the IEP timer and watch for the appropriate event
   92 :                   :     // (bit set in r31) instead of polling the IEP status register.
   93 :                   :     //  WBC     r31, 30
   94 :                   : 
   95 : 0x0054 0x91443a82 :     LBCO    r2, CONST_IEP, 0x44, 4      // Load CMP_STATUS register
   96 : 0x0055 0xcf00e2ff :     QBBC    WAITLOOP, r2, 0             // Wait until counter times out
   97 : 0x0056 0x81443a82 :     SBCO    r2, CONST_IEP, 0x44, 4      // Clear counter timeout bit
   98 :                   : 
   99 :                   :     // The timer just ticked...
  100 :                   :     // ...write out the pre-computed output bits:
  101 : 0x0057 0x10f6f6fe :     MOV     r30, GState.PRU_Out
  102 : 0x0058 0xe100648e :     SBBO    GState.GPIO0_CLR, State.GPIO0_CLR_ADDR, 0, 8    // Writes both CLR and SET registers
  103 : 0x0059 0xe1006590 :     SBBO    GState.GPIO1_CLR, State.GPIO1_CLR_ADDR, 0, 8    // Writes both CLR and SET registers
  104 : 0x005a 0xe1006692 :     SBBO    GState.GPIO2_CLR, State.GPIO2_CLR_ADDR, 0, 8    // Writes both CLR and SET registers
  105 : 0x005b 0xe1006794 :     SBBO    GState.GPIO3_CLR, State.GPIO3_CLR_ADDR, 0, 8    // Writes both CLR and SET registers
  106 :                   : 
  107 :                   :     // Clear the GPIO set/clear registers
  108 : 0x005c 0x2eff8f8e :     ZERO    &GState.GPIO0_Clr, OFFSET(GState.PRU_Out) - OFFSET(GState.GPIO0_Clr)
  109 :                   : 
  110 :                   :     // Save channel state data
  111 : 0x005d 0xe1030d6c :     SBBO    GTask.dataY, GTask.addr, OFFSET(task_header.dataY), SIZE(task_header.dataY)
  112 :                   : 
  113 :                   :     // We're done here...carry on with the next task
  114 : 0x005e 0x21001e00 :     JMP     NEXT_TASK
  115 :                   : 
  116 :                   : .leave WAIT_SCOPE
  117 :                   : 

Source File 5 : 'pru_stepdir.p' (46 Instructions Generated)

    1 :                   : //----------------------------------------------------------------------//
    2 :                   : // Description: pru.stepdir.p                                           //
    3 :                   : // PRU code implementing step/dir generation task                       //
    4 :                   : //                                                                      //
    5 :                   : // Author(s): Charles Steinkuehler                                      //
    6 :                   : // License: GNU GPL Version 2.0 or (at your option) any later version.  //
    7 :                   : //                                                                      //
    8 :                   : // Major Changes:                                                       //
    9 :                   : // 2013-May    Charles Steinkuehler                                     //
   10 :                   : //             Split into several files                                 //
   11 :                   : //             Altered main loop to support a linked list of tasks      //
   12 :                   : //             Added support for GPIO pins in addition to PRU outputs   //
   13 :                   : // 2012-Dec-27 Charles Steinkuehler                                     //
   14 :                   : //             Initial version                                          //
   15 :                   : //----------------------------------------------------------------------//
   16 :                   : // This file is part of LinuxCNC HAL                                    //
   17 :                   : //                                                                      //
   18 :                   : // Copyright (C) 2013  Charles Steinkuehler                             //
   19 :                   : //                     <charles AT steinkuehler DOT net>                //
   20 :                   : //                                                                      //
   21 :                   : // This program is free software; you can redistribute it and/or        //
   22 :                   : // modify it under the terms of the GNU General Public License          //
   23 :                   : // as published by the Free Software Foundation; either version 2       //
   24 :                   : // of the License, or (at your option) any later version.               //
   25 :                   : //                                                                      //
   26 :                   : // This program is distributed in the hope that it will be useful,      //
   27 :                   : // but WITHOUT ANY WARRANTY; without even the implied warranty of       //
   28 :                   : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
   29 :                   : // GNU General Public License for more details.                         //
   30 :                   : //                                                                      //
   31 :                   : // You should have received a copy of the GNU General Public License    //
   32 :                   : // along with this program; if not, write to the Free Software          //
   33 :                   : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA        //
   34 :                   : // 02110-1301, USA.                                                     //
   35 :                   : //                                                                      //
   36 :                   : // THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR       //
   37 :                   : // ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE   //
   38 :                   : // TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of      //
   39 :                   : // harming persons must have provisions for completely removing power   //
   40 :                   : // from all motors, etc, before persons enter any danger area.  All     //
   41 :                   : // machinery must be designed to comply with local and national safety  //
   42 :                   : // codes, and the authors of this software can not, and do not, take    //
   43 :                   : // any responsibility for such compliance.                              //
   44 :                   : //                                                                      //
   45 :                   : // This code was written as part of the LinuxCNC project.  For more     //
   46 :                   : // information, go to www.linuxcnc.org.                                 //
   47 :                   : //----------------------------------------------------------------------//
   48 :                   : 
   49 :                   : MODE_STEP_DIR:
   50 :                   : .enter STEP_DIR_SCOPE
   51 :                   : 
   52 :                   : .assign stepgen_state, GState.State_Reg0, GState.State_Reg6, State
   53 :                   : 
   54 :                   : #define DirHoldBit      31
   55 :                   : #define DirChgBit       30
   56 :                   : #define PulseHoldBit    29
   57 :                   : #define GuardBit        28
   58 :                   : #define StepBit         27
   59 :                   : 
   60 :                   : #define HoldMask        0x1F
   61 :                   : #define DirHoldMask     0x3F
   62 :                   : 
   63 :                   :     // Read in task state data
   64 : 0x005f 0xf308ad84 :     LBBO State, GTask.addr, SIZE(task_header), SIZE(State)
   65 :                   : 
   66 :                   :     // Accumulator MSBs are used for state/status encoding:
   67 :                   :     // t31 = Dir Hold (set if we're waiting for direction setup/hold)
   68 :                   :     // t30 = Dir Changed (set if rate changed direction and we need to update the direction output)
   69 :                   :     // t29 = Pulse Hold (set if we're waiting for minimum high/low pulse length)
   70 :                   :     // t28 = Guard bit (protects higher status bits from accumulator wrapping)
   71 :                   :     // t27 = Overflow bit (indicates we should generate a step)
   72 :                   : 
   73 :                   :     // If the accumulator overflow bit is set here, we are holding for some reason
   74 :                   :     // (bits 29-31 should tell us why, but we'll deal with that later)
   75 : 0x0060 0xd11be702 :     QBBS    SD_ACC_HOLD, State.Accum, StepBit
   76 : 0x0061 0x00e4e7e7 :     ADD     State.Accum, State.Accum, State.Rate
   77 :                   : SD_ACC_HOLD:
   78 :                   : 
   79 :                   :     // Check if direction changed
   80 : 0x0062 0x146a6401 :     XOR     r1.b0, State.Rate.b3, State.RateQ
   81 : 0x0063 0x1064646a :     MOV     State.RateQ, State.Rate.b3
   82 : 0x0064 0xc9070102 :     QBBC    SD_DIR_CHG_DONE, r1.b0, 7
   83 :                   : 
   84 :                   :     // Flag direction change
   85 : 0x0065 0x1f1ee7e7 :     SET     State.Accum, DirChgBit
   86 :                   : 
   87 :                   : SD_DIR_CHG_DONE:
   88 :                   : 
   89 :                   :     // Update the pulse timings, if required
   90 : 0x0066 0xc91de70b :     QBBC    SD_PULSE_DONE, State.Accum, PulseHoldBit
   91 :                   : 
   92 :                   :     // Decrement timeout
   93 : 0x0067 0x05018989 :     SUB     State.T_Pulse, State.T_Pulse, 1
   94 : 0x0068 0x69008909 :     QBNE    SD_PULSE_DONE, State.T_Pulse, 0
   95 :                   : 
   96 :                   :     // Pulse timer expired
   97 :                   : 
   98 :                   :     // Check to see if step output is active
   99 : 0x0069 0x51004a07 :     QBEQ    SD_PULSE_DELAY_OVER, State.StepQ, 0
  100 :                   : 
  101 :                   :     // Step pulse output is active, clear it and setup pulse low delay
  102 : 0x006a 0x104c4c23 :     MOV     r3.b1, GTask.dataX
  103 : 0x006b 0x24000103 :     LDI     r3.b0, 1
  104 : 0x006c 0x230020d8 :     CALL    SET_CLR_BIT
  105 : 0x006d 0x2400004a :     LDI     State.StepQ, 0
  106 : 0x006e 0x10868689 :     MOV     State.T_Pulse, State.Dly_step_low
  107 : 0x006f 0x21007100 :     JMP     SD_PULSE_DONE
  108 :                   : 
  109 :                   : SD_PULSE_DELAY_OVER:
  110 :                   : 
  111 :                   :     // Step pulse output is low and pulse low timer expired,
  112 :                   :     // so clear Pulse Hold bit in accumulator and we're done
  113 : 0x0070 0x1d1de7e7 :     CLR     State.Accum, PulseHoldBit
  114 :                   : 
  115 :                   : SD_PULSE_DONE:
  116 :                   : 
  117 :                   :     // Decrement Direction timer if non-zero
  118 : 0x0071 0x5100c902 :     QBEQ    SD_DIR_SKIP_SUB, State.T_Dir, 0
  119 : 0x0072 0x0501c9c9 :     SUB     State.T_Dir, State.T_Dir, 1
  120 :                   : 
  121 :                   : SD_DIR_SKIP_SUB:
  122 :                   : 
  123 :                   :     // Process direction updates if required (either DirHoldBit or DirChgBit is set)
  124 : 0x0073 0x713f670b :     QBGE    SD_DIR_DONE, State.Accum.b3, DirHoldMask
  125 :                   : 
  126 :                   :     // Wait for any pending timeout
  127 : 0x0074 0x6900c90a :     QBNE    SD_DIR_DONE, State.T_Dir, 0
  128 :                   : 
  129 :                   :     // Direction timer expired
  130 :                   : 
  131 : 0x0075 0xc91ee708 :     QBBC    SD_DIR_SETUP_DLY, State.Accum, DirChgBit
  132 :                   : 
  133 :                   :     // Dir Changed bit is set, we need to update Dir output and configure dir setup timer
  134 :                   : 
  135 :                   :     // Update Direction output
  136 : 0x0076 0x106c6c23 :     MOV     r3.b1, GTask.dataY
  137 : 0x0077 0x0b1fe403 :     LSR     r3.b0, State.Rate, 31
  138 : 0x0078 0x230020d8 :     CALL    SET_CLR_BIT
  139 :                   : 
  140 :                   :     // Clear Dir Changed Bit
  141 : 0x0079 0x1d1ee7e7 :     CLR     State.Accum, DirChgBit
  142 : 0x007a 0x1f1fe7e7 :     SET     State.Accum, DirHoldBit
  143 : 0x007b 0x10c6c689 :     MOV     State.T_Pulse, State.Dly_dir_setup
  144 : 0x007c 0x21007e00 :     JMP     SD_DIR_DONE
  145 :                   : 
  146 :                   : SD_DIR_SETUP_DLY:
  147 : 0x007d 0x1d1fe7e7 :     CLR     State.Accum, DirHoldBit
  148 :                   : 
  149 :                   : SD_DIR_DONE:
  150 :                   : 
  151 : 0x007e 0xc91be70d :     QBBC    STEP_DONE, State.Accum, StepBit
  152 : 0x007f 0x491f670c :     QBLT    STEP_DONE, State.Accum.b3, HoldMask
  153 :                   : 
  154 :                   :     // Time for a step!
  155 :                   : 
  156 :                   :     // Reset Accumulator status bits
  157 : 0x0080 0x1d1be7e7 :     CLR     State.Accum, StepBit
  158 :                   : 
  159 : 0x0081 0x13306767 :     OR      State.Accum.b3, State.Accum.b3, 0x30    // Set GuardBit and PulseHoldBit
  160 :                   : //    SET     State.Accum, GuardBit
  161 :                   : //    SET     State.Accum, PulseHoldBit
  162 :                   : 
  163 :                   :     // Update position register
  164 : 0x0082 0x0101e8e8 :     ADD     State.Pos, State.Pos, 1
  165 : 0x0083 0xc91fe402 :     QBBC    SD_DIR_UP, State.Rate, 31
  166 : 0x0084 0x0502e8e8 :     SUB     State.Pos, State.Pos, 2
  167 :                   : SD_DIR_UP:
  168 :                   : 
  169 :                   :     // Update state
  170 : 0x0085 0x104c4c23 :     MOV     r3.b1, GTask.dataX
  171 : 0x0086 0x24000003 :     LDI     r3.b0, 0
  172 : 0x0087 0x230020d8 :     CALL    SET_CLR_BIT
  173 : 0x0088 0x1f004a4a :     SET     State.StepQ, 0
  174 :                   :     // Fixme: The following should be one 32-bit MOV
  175 : 0x0089 0x10858589 :     MOV     State.T_Pulse, State.Dly_step_high
  176 : 0x008a 0x10c5c5c9 :     MOV     State.T_Dir, State.Dly_dir_hold
  177 :                   : 
  178 :                   : STEP_DONE:
  179 :                   :     // Save channel state data
  180 : 0x008b 0xe114ed87 :     SBBO    State.Accum, GTask.addr, SIZE(task_header) + OFFSET(State.Accum), SIZE(State) - OFFSET(State.Accum)
  181 :                   : 
  182 :                   :     // We're done here...carry on with the next task
  183 : 0x008c 0x21001e00 :     JMP     NEXT_TASK
  184 :                   : 
  185 :                   : .leave STEP_DIR_SCOPE
  186 :                   : 
  187 :                   : 

Source File 6 : 'pru_deltasigma.p' (18 Instructions Generated)

    1 :                   : //----------------------------------------------------------------------//
    2 :                   : // Description: pru.deltasigma.p                                        //
    3 :                   : // PRU code implementing Delta Sigma modulation task                    //
    4 :                   : //                                                                      //
    5 :                   : // Author(s): Charles Steinkuehler                                      //
    6 :                   : // License: GNU GPL Version 2.0 or (at your option) any later version.  //
    7 :                   : //                                                                      //
    8 :                   : // Last change:                                                         //
    9 :                   : // 2013-May-20 Charles Steinkuehler                                     //
   10 :                   : //             Split into several files                                 //
   11 :                   : //             Altered main loop to support a linked list of tasks      //
   12 :                   : // 2012-Dec-27 Charles Steinkuehler                                     //
   13 :                   : //             Initial version                                          //
   14 :                   : //----------------------------------------------------------------------//
   15 :                   : // This file is part of LinuxCNC HAL                                    //
   16 :                   : //                                                                      //
   17 :                   : // Copyright (C) 2013  Charles Steinkuehler                             //
   18 :                   : //                     <charles AT steinkuehler DOT net>                //
   19 :                   : //                                                                      //
   20 :                   : // This program is free software; you can redistribute it and/or        //
   21 :                   : // modify it under the terms of the GNU General Public License          //
   22 :                   : // as published by the Free Software Foundation; either version 2       //
   23 :                   : // of the License, or (at your option) any later version.               //
   24 :                   : //                                                                      //
   25 :                   : // This program is distributed in the hope that it will be useful,      //
   26 :                   : // but WITHOUT ANY WARRANTY; without even the implied warranty of       //
   27 :                   : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
   28 :                   : // GNU General Public License for more details.                         //
   29 :                   : //                                                                      //
   30 :                   : // You should have received a copy of the GNU General Public License    //
   31 :                   : // along with this program; if not, write to the Free Software          //
   32 :                   : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA        //
   33 :                   : // 02110-1301, USA.                                                     //
   34 :                   : //                                                                      //
   35 :                   : // THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR       //
   36 :                   : // ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE   //
   37 :                   : // TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of      //
   38 :                   : // harming persons must have provisions for completely removing power   //
   39 :                   : // from all motors, etc, before persons enter any danger area.  All     //
   40 :                   : // machinery must be designed to comply with local and national safety  //
   41 :                   : // codes, and the authors of this software can not, and do not, take    //
   42 :                   : // any responsibility for such compliance.                              //
   43 :                   : //                                                                      //
   44 :                   : // This code was written as part of the LinuxCNC project.  For more     //
   45 :                   : // information, go to www.linuxcnc.org.                                 //
   46 :                   : //----------------------------------------------------------------------//
   47 :                   : 
   48 :                   : MODE_DELTA_SIG:
   49 :                   : .enter DELTA_SIG_SCOPE
   50 :                   : 
   51 :                   : .assign delta_state,  GState.State_Reg0, GState.State_Reg0, State
   52 :                   : .assign delta_index,  GState.State_Reg1, GState.State_Reg1, Index
   53 :                   : .assign delta_output, GState.State_reg2, GState.State_Reg3, Output
   54 :                   : 
   55 :                   :     // Skip everything if no outputs are configured
   56 : 0x008d 0x51002c11 :     QBEQ    DELTA_DONE, GTask.len, 0
   57 :                   : 
   58 :                   :     // Read in task state data
   59 : 0x008e 0xf1082d84 :     LBBO State, GTask.addr, SIZE(task_header), SIZE(State)
   60 :                   : 
   61 :                   :     // Cycle through all configured outputs one at a time
   62 : 0x008f 0x24000c85 :     LDI     Index.Offset, SIZE(task_header) + SIZE(State)
   63 :                   : 
   64 :                   : DELTA_OUT_LOOP:
   65 : 0x0090 0xf0856d86 :     LBBO    Output, GTask.addr, Index.Offset, SIZE(Output)
   66 :                   : 
   67 :                   :     // Update integrator state
   68 : 0x0091 0x04c786e1 :     SUB     r1, Output.Value, Output.Quantize
   69 : 0x0092 0x00818787 :     ADD     Output.Integrate, Output.Integrate, r1.w0
   70 :                   :     
   71 :                   :     // Calculate Output State and store quantized value for next loop
   72 : 0x0093 0xc90f8703 :     QBBC    DELTA_OUT_Zero, Output.Integrate, 15
   73 : 0x0094 0x24c000c7 :     LDI     Output.Quantize, 0xC000
   74 : 0x0095 0x21009700 :     JMP     DELTA_DO_PIN
   75 :                   : 
   76 :                   :     DELTA_OUT_Zero:
   77 : 0x0096 0x240000c7 :     LDI     Output.Quantize, 0x0000
   78 :                   : 
   79 :                   :     DELTA_DO_PIN:
   80 : 0x0097 0x10464623 :     MOV     r3.b1, Output.Pin
   81 : 0x0098 0x1901c703 :     MIN     r3.b0, Output.Quantize, 1
   82 : 0x0099 0x230020d8 :     CALL    SET_CLR_BIT
   83 :                   : 
   84 :                   :     // Save output state data
   85 : 0x009a 0xe0852d87 :     SBBO    Output.Integrate, GTask.addr, Index.Offset, SIZE(Output) - OFFSET(Output.Integrate)
   86 :                   : 
   87 :                   :     // ...and loop until we're done
   88 : 0x009b 0x01088585 :     ADD     Index.Offset, Index.Offset, SIZE(Output)
   89 : 0x009c 0x05012c2c :     SUB     GTask.len, GTask.len, 1
   90 :                   : 
   91 : 0x009d 0x6f002cf3 :     QBNE    DELTA_OUT_LOOP, GTask.len, 0
   92 :                   : 
   93 :                   : DELTA_DONE:
   94 :                   :     // We're done here...carry on with the next task
   95 : 0x009e 0x21001e00 :     JMP     NEXT_TASK
   96 :                   : 
   97 :                   : .leave DELTA_SIG_SCOPE
   98 :                   : 

Source File 7 : 'pru_pwm.p' (28 Instructions Generated)

    1 :                   : //----------------------------------------------------------------------//
    2 :                   : // Description: pru.pwm.p                                               //
    3 :                   : // PRU code implementing PWM task                                       //
    4 :                   : //                                                                      //
    5 :                   : // Author(s): Charles Steinkuehler                                      //
    6 :                   : // License: GNU GPL Version 2.0 or (at your option) any later version.  //
    7 :                   : //                                                                      //
    8 :                   : // Major Changes:                                                       //
    9 :                   : // 2013-May    Charles Steinkuehler                                     //
   10 :                   : //             Split into several files                                 //
   11 :                   : //             Altered main loop to support a linked list of tasks      //
   12 :                   : //             Added support for GPIO pins in addition to PRU outputs   //
   13 :                   : // 2012-Dec-27 Charles Steinkuehler                                     //
   14 :                   : //             Initial version                                          //
   15 :                   : //----------------------------------------------------------------------//
   16 :                   : // This file is part of LinuxCNC HAL                                    //
   17 :                   : //                                                                      //
   18 :                   : // Copyright (C) 2013  Charles Steinkuehler                             //
   19 :                   : //                     <charles AT steinkuehler DOT net>                //
   20 :                   : //                                                                      //
   21 :                   : // This program is free software; you can redistribute it and/or        //
   22 :                   : // modify it under the terms of the GNU General Public License          //
   23 :                   : // as published by the Free Software Foundation; either version 2       //
   24 :                   : // of the License, or (at your option) any later version.               //
   25 :                   : //                                                                      //
   26 :                   : // This program is distributed in the hope that it will be useful,      //
   27 :                   : // but WITHOUT ANY WARRANTY; without even the implied warranty of       //
   28 :                   : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        //
   29 :                   : // GNU General Public License for more details.                         //
   30 :                   : //                                                                      //
   31 :                   : // You should have received a copy of the GNU General Public License    //
   32 :                   : // along with this program; if not, write to the Free Software          //
   33 :                   : // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA        //
   34 :                   : // 02110-1301, USA.                                                     //
   35 :                   : //                                                                      //
   36 :                   : // THE AUTHORS OF THIS PROGRAM ACCEPT ABSOLUTELY NO LIABILITY FOR       //
   37 :                   : // ANY HARM OR LOSS RESULTING FROM ITS USE.  IT IS _EXTREMELY_ UNWISE   //
   38 :                   : // TO RELY ON SOFTWARE ALONE FOR SAFETY.  Any machinery capable of      //
   39 :                   : // harming persons must have provisions for completely removing power   //
   40 :                   : // from all motors, etc, before persons enter any danger area.  All     //
   41 :                   : // machinery must be designed to comply with local and national safety  //
   42 :                   : // codes, and the authors of this software can not, and do not, take    //
   43 :                   : // any responsibility for such compliance.                              //
   44 :                   : //                                                                      //
   45 :                   : // This code was written as part of the LinuxCNC project.  For more     //
   46 :                   : // information, go to www.linuxcnc.org.                                 //
   47 :                   : //----------------------------------------------------------------------//
   48 :                   : 
   49 :                   : MODE_PWM:
   50 :                   : .enter PWM_SCOPE
   51 :                   : 
   52 :                   : .assign pwm_state,  GState.State_Reg0, GState.State_Reg1, State
   53 :                   : .assign pwm_index,  GState.State_Reg2, GState.State_Reg2, Index
   54 :                   : .assign pwm_output, GState.State_reg3, GState.State_Reg3, Output
   55 :                   : 
   56 :                   :     // Skip everything if no outputs are configured
   57 : 0x009f 0x51002c1a :     QBEQ    PWM_DONE, GTask.len, 0
   58 :                   : 
   59 :                   :     // Read in task state data
   60 : 0x00a0 0xf1086d84 :     LBBO State, GTask.addr, SIZE(task_header), SIZE(State)
   61 :                   : 
   62 :                   :     // Increment Prescale Counter
   63 : 0x00a1 0x01018585 :     ADD     State.T_Prescale, State.T_Prescale, 1
   64 :                   : 
   65 :                   :     // Prescale finished?
   66 : 0x00a2 0x48858417 :     QBLT    PWM_DONE, State.Prescale, State.T_Prescale
   67 : 0x00a3 0x24000085 :     LDI     State.T_Prescale, 0
   68 :                   : 
   69 :                   :     // Increment Period Counter
   70 : 0x00a4 0x0101c5c5 :     ADD     State.T_Period, State.T_Period, 1
   71 :                   : 
   72 :                   :     // Are we finished with this period?
   73 : 0x00a5 0x58c5c40b :     QBLE    PrescaleNE, State.Period, State.T_Period
   74 : 0x00a6 0x240000c5 :     LDI     State.T_Period, 0
   75 :                   : 
   76 : 0x00a7 0x24001086 :     LDI     Index.Offset, SIZE(task_header) + SIZE(State)
   77 :                   : 
   78 :                   :     // Set all outputs when period wraps
   79 :                   : PWM_SET_LOOP:
   80 : 0x00a8 0xf0862d87 :     LBBO    Output, GTask.addr, Index.Offset, SIZE(Output)
   81 :                   : 
   82 :                   :     // Only set if Value != 0, otherwise clear
   83 : 0x00a9 0x10474723 :     MOV     r3.b1, Output.Pin
   84 : 0x00aa 0x19018703 :     MIN     r3.b0, Output.Value, 1
   85 : 0x00ab 0x230020d8 :     CALL    SET_CLR_BIT
   86 :                   : 
   87 : 0x00ac 0x01048686 :     ADD     Index.Offset, Index.Offset, SIZE(Output)
   88 : 0x00ad 0x05012c2c :     SUB     GTask.len, GTask.len, 1
   89 : 0x00ae 0x6f002cfa :     QBNE    PWM_SET_LOOP, GTask.len, 0
   90 : 0x00af 0x2100b900 :     JMP     PWM_DONE
   91 :                   : 
   92 :                   :     PrescaleNE:
   93 :                   : 
   94 :                   :     // Cycle through outputs and see if we need to clear any
   95 : 0x00b0 0x24001086 :     LDI     Index.Offset, SIZE(task_header) + SIZE(State)
   96 :                   : 
   97 :                   : PWM_OUT_LOOP:
   98 : 0x00b1 0xf0862d87 :     LBBO    Output.Value, GTask.addr, Index.Offset, SIZE(Output)
   99 :                   : 
  100 : 0x00b2 0x6887c504 :     QBNE    ValueNE, State.T_Period, Output.Value
  101 :                   : //  CLR     GState.PRU_Out, Output.Pin
  102 :                   : 
  103 : 0x00b3 0x10474723 :     MOV     r3.b1, Output.Pin
  104 : 0x00b4 0x24000003 :     LDI     r3.b0, 0
  105 : 0x00b5 0x230020d8 :     CALL    SET_CLR_BIT
  106 :                   : 
  107 :                   :     ValueNE:
  108 :                   : 
  109 : 0x00b6 0x01048686 :     ADD     Index.Offset, Index.Offset, SIZE(Output)
  110 : 0x00b7 0x05012c2c :     SUB     GTask.len, GTask.len, 1
  111 :                   : 
  112 : 0x00b8 0x6f002cf9 :     QBNE    PWM_OUT_LOOP, GTask.len, 0
  113 :                   : 
  114 :                   : PWM_DONE:
  115 :                   :     // Save channel state data
  116 : 0x00b9 0xe10c2d85 :     SBBO    State.T_Prescale, GTask.addr, SIZE(task_header) + OFFSET(State.T_Prescale), SIZE(State) - OFFSET(State.T_Prescale)
  117 :                   : 
  118 :                   :     // We're done here...carry on with the next task
  119 : 0x00ba 0x21001e00 :     JMP     NEXT_TASK
  120 :                   : 
  121 :                   : .leave PWM_SCOPE
  122 :                   : 

