Mouse code for the MacroRat
mbed-dev/targets/TARGET_ARM_SSG/TARGET_MPS2/SDK/fpga.c@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* mbed Microcontroller Library |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2006-2015 ARM Limited |
sahilmgandhi | 18:6a4db94011d3 | 3 | * |
sahilmgandhi | 18:6a4db94011d3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sahilmgandhi | 18:6a4db94011d3 | 5 | * you may not use this file except in compliance with the License. |
sahilmgandhi | 18:6a4db94011d3 | 6 | * You may obtain a copy of the License at |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Unless required by applicable law or agreed to in writing, software |
sahilmgandhi | 18:6a4db94011d3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sahilmgandhi | 18:6a4db94011d3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sahilmgandhi | 18:6a4db94011d3 | 13 | * See the License for the specific language governing permissions and |
sahilmgandhi | 18:6a4db94011d3 | 14 | * limitations under the License. |
sahilmgandhi | 18:6a4db94011d3 | 15 | * ---------------------------------------------------------------- |
sahilmgandhi | 18:6a4db94011d3 | 16 | * File: fpga.c |
sahilmgandhi | 18:6a4db94011d3 | 17 | * Release: Version 1.0 |
sahilmgandhi | 18:6a4db94011d3 | 18 | * ---------------------------------------------------------------- |
sahilmgandhi | 18:6a4db94011d3 | 19 | */ |
sahilmgandhi | 18:6a4db94011d3 | 20 | |
sahilmgandhi | 18:6a4db94011d3 | 21 | /* |
sahilmgandhi | 18:6a4db94011d3 | 22 | * Code implementation file for the fpga functions. |
sahilmgandhi | 18:6a4db94011d3 | 23 | */ |
sahilmgandhi | 18:6a4db94011d3 | 24 | |
sahilmgandhi | 18:6a4db94011d3 | 25 | #include "SMM_MPS2.h" // MPS2 common header |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | // Function to delay n*ticks (25MHz = 40nS per tick) |
sahilmgandhi | 18:6a4db94011d3 | 28 | // Used for I2C drivers |
sahilmgandhi | 18:6a4db94011d3 | 29 | void i2c_delay(unsigned int tick) |
sahilmgandhi | 18:6a4db94011d3 | 30 | { |
sahilmgandhi | 18:6a4db94011d3 | 31 | unsigned int end; |
sahilmgandhi | 18:6a4db94011d3 | 32 | unsigned int start; |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | start = MPS2_FPGAIO->COUNTER; |
sahilmgandhi | 18:6a4db94011d3 | 35 | end = start + (tick); |
sahilmgandhi | 18:6a4db94011d3 | 36 | |
sahilmgandhi | 18:6a4db94011d3 | 37 | if(end >= start) |
sahilmgandhi | 18:6a4db94011d3 | 38 | { |
sahilmgandhi | 18:6a4db94011d3 | 39 | while (MPS2_FPGAIO->COUNTER >= start && MPS2_FPGAIO->COUNTER < end); |
sahilmgandhi | 18:6a4db94011d3 | 40 | } |
sahilmgandhi | 18:6a4db94011d3 | 41 | else |
sahilmgandhi | 18:6a4db94011d3 | 42 | { |
sahilmgandhi | 18:6a4db94011d3 | 43 | while (MPS2_FPGAIO->COUNTER >= start); |
sahilmgandhi | 18:6a4db94011d3 | 44 | while (MPS2_FPGAIO->COUNTER < end); |
sahilmgandhi | 18:6a4db94011d3 | 45 | } |
sahilmgandhi | 18:6a4db94011d3 | 46 | } |
sahilmgandhi | 18:6a4db94011d3 | 47 | |
sahilmgandhi | 18:6a4db94011d3 | 48 | /* Sleep function to delay n*mS |
sahilmgandhi | 18:6a4db94011d3 | 49 | * Uses FPGA counter. |
sahilmgandhi | 18:6a4db94011d3 | 50 | */ |
sahilmgandhi | 18:6a4db94011d3 | 51 | void Sleepms(unsigned int msec) |
sahilmgandhi | 18:6a4db94011d3 | 52 | { |
sahilmgandhi | 18:6a4db94011d3 | 53 | unsigned int end; |
sahilmgandhi | 18:6a4db94011d3 | 54 | unsigned int start; |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | start = MPS2_FPGAIO->COUNTER; |
sahilmgandhi | 18:6a4db94011d3 | 57 | end = start + (25 * msec * 1000); |
sahilmgandhi | 18:6a4db94011d3 | 58 | |
sahilmgandhi | 18:6a4db94011d3 | 59 | if(end >= start) |
sahilmgandhi | 18:6a4db94011d3 | 60 | { |
sahilmgandhi | 18:6a4db94011d3 | 61 | while (MPS2_FPGAIO->COUNTER >= start && MPS2_FPGAIO->COUNTER < end); |
sahilmgandhi | 18:6a4db94011d3 | 62 | } |
sahilmgandhi | 18:6a4db94011d3 | 63 | else |
sahilmgandhi | 18:6a4db94011d3 | 64 | { |
sahilmgandhi | 18:6a4db94011d3 | 65 | while (MPS2_FPGAIO->COUNTER >= start); |
sahilmgandhi | 18:6a4db94011d3 | 66 | while (MPS2_FPGAIO->COUNTER < end); |
sahilmgandhi | 18:6a4db94011d3 | 67 | } |
sahilmgandhi | 18:6a4db94011d3 | 68 | } |
sahilmgandhi | 18:6a4db94011d3 | 69 | |
sahilmgandhi | 18:6a4db94011d3 | 70 | /* Sleep function to delay n*uS |
sahilmgandhi | 18:6a4db94011d3 | 71 | */ |
sahilmgandhi | 18:6a4db94011d3 | 72 | void Sleepus(unsigned int usec) |
sahilmgandhi | 18:6a4db94011d3 | 73 | { |
sahilmgandhi | 18:6a4db94011d3 | 74 | unsigned int end; |
sahilmgandhi | 18:6a4db94011d3 | 75 | unsigned int start; |
sahilmgandhi | 18:6a4db94011d3 | 76 | |
sahilmgandhi | 18:6a4db94011d3 | 77 | start = MPS2_FPGAIO->COUNTER; |
sahilmgandhi | 18:6a4db94011d3 | 78 | end = start + (25 * usec); |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | if(end >= start) |
sahilmgandhi | 18:6a4db94011d3 | 81 | { |
sahilmgandhi | 18:6a4db94011d3 | 82 | while (MPS2_FPGAIO->COUNTER >= start && MPS2_FPGAIO->COUNTER < end); |
sahilmgandhi | 18:6a4db94011d3 | 83 | } |
sahilmgandhi | 18:6a4db94011d3 | 84 | else |
sahilmgandhi | 18:6a4db94011d3 | 85 | { |
sahilmgandhi | 18:6a4db94011d3 | 86 | while (MPS2_FPGAIO->COUNTER >= start); |
sahilmgandhi | 18:6a4db94011d3 | 87 | while (MPS2_FPGAIO->COUNTER < end); |
sahilmgandhi | 18:6a4db94011d3 | 88 | } |
sahilmgandhi | 18:6a4db94011d3 | 89 | } |
sahilmgandhi | 18:6a4db94011d3 | 90 |