Ivo van Poorten
/
SiLabs_C2
Basis for the C2 protocol from Silicon Labs.
main.cpp@1:7a82f806fe92, 2014-05-24 (annotated)
- Committer:
- Ivop
- Date:
- Sat May 24 11:54:33 2014 +0000
- Revision:
- 1:7a82f806fe92
- Parent:
- 0:902f10e5d3e0
- Child:
- 2:9092d0d1558b
license at the top, reset and strobe functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ivop | 1:7a82f806fe92 | 1 | /* |
Ivop | 1:7a82f806fe92 | 2 | * SiLabs C2 Protocol on mbed pins p5/p6 |
Ivop | 1:7a82f806fe92 | 3 | * |
Ivop | 1:7a82f806fe92 | 4 | * Copyright (c) 2014, Ivo van Poorten <ivopvp@gmail.com> |
Ivop | 1:7a82f806fe92 | 5 | * All rights reserved. |
Ivop | 1:7a82f806fe92 | 6 | * |
Ivop | 1:7a82f806fe92 | 7 | * Redistribution and use in source and binary forms, with or without |
Ivop | 1:7a82f806fe92 | 8 | * modification, are permitted provided that the following conditions |
Ivop | 1:7a82f806fe92 | 9 | * are met: |
Ivop | 1:7a82f806fe92 | 10 | * 1. Redistributions of source code must retain the above copyright |
Ivop | 1:7a82f806fe92 | 11 | * notice, this list of conditions and the following disclaimer. |
Ivop | 1:7a82f806fe92 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
Ivop | 1:7a82f806fe92 | 13 | * notice, this list of conditions and the following disclaimer in the |
Ivop | 1:7a82f806fe92 | 14 | * documentation and/or other materials provided with the distribution. |
Ivop | 1:7a82f806fe92 | 15 | * |
Ivop | 1:7a82f806fe92 | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
Ivop | 1:7a82f806fe92 | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
Ivop | 1:7a82f806fe92 | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
Ivop | 1:7a82f806fe92 | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
Ivop | 1:7a82f806fe92 | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
Ivop | 1:7a82f806fe92 | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
Ivop | 1:7a82f806fe92 | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
Ivop | 1:7a82f806fe92 | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Ivop | 1:7a82f806fe92 | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
Ivop | 1:7a82f806fe92 | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ivop | 1:7a82f806fe92 | 26 | */ |
Ivop | 1:7a82f806fe92 | 27 | |
Ivop | 0:902f10e5d3e0 | 28 | #include "mbed.h" |
Ivop | 0:902f10e5d3e0 | 29 | |
Ivop | 0:902f10e5d3e0 | 30 | DigitalOut c2ck(p5); |
Ivop | 0:902f10e5d3e0 | 31 | DigitalInOut c2d(p6); |
Ivop | 0:902f10e5d3e0 | 32 | |
Ivop | 1:7a82f806fe92 | 33 | static void c2ck_reset(void) { |
Ivop | 1:7a82f806fe92 | 34 | c2ck = 0; |
Ivop | 1:7a82f806fe92 | 35 | wait_us(25); |
Ivop | 1:7a82f806fe92 | 36 | c2ck = 1; |
Ivop | 1:7a82f806fe92 | 37 | wait_us(1); |
Ivop | 1:7a82f806fe92 | 38 | } |
Ivop | 1:7a82f806fe92 | 39 | |
Ivop | 1:7a82f806fe92 | 40 | static void c2ck_strobe(void) { |
Ivop | 1:7a82f806fe92 | 41 | c2ck = 0; |
Ivop | 1:7a82f806fe92 | 42 | wait_us(1); |
Ivop | 1:7a82f806fe92 | 43 | c2ck = 1; |
Ivop | 1:7a82f806fe92 | 44 | wait_us(1); |
Ivop | 1:7a82f806fe92 | 45 | } |
Ivop | 1:7a82f806fe92 | 46 | |
Ivop | 1:7a82f806fe92 | 47 | // Four basic C2 Instructions |
Ivop | 1:7a82f806fe92 | 48 | // |
Ivop | 1:7a82f806fe92 | 49 | // 00b Data Read |
Ivop | 1:7a82f806fe92 | 50 | // 01b Data Write |
Ivop | 1:7a82f806fe92 | 51 | // 10b Address Read |
Ivop | 1:7a82f806fe92 | 52 | // 11b Address Write |
Ivop | 1:7a82f806fe92 | 53 | |
Ivop | 1:7a82f806fe92 | 54 | |
Ivop | 0:902f10e5d3e0 | 55 | int main() { |
Ivop | 1:7a82f806fe92 | 56 | int c; |
Ivop | 1:7a82f806fe92 | 57 | |
Ivop | 1:7a82f806fe92 | 58 | c2d.input(); |
Ivop | 1:7a82f806fe92 | 59 | c2ck = 1; |
Ivop | 1:7a82f806fe92 | 60 | |
Ivop | 1:7a82f806fe92 | 61 | printf("SiLabs C2 Protocol\n\r\n\r"); |
Ivop | 1:7a82f806fe92 | 62 | printf("Connect C2CK (clock) to p5 and C2D (data) to p6\n\r\n\r"); |
Ivop | 1:7a82f806fe92 | 63 | printf("Press any key to continue\n\r"); |
Ivop | 1:7a82f806fe92 | 64 | |
Ivop | 1:7a82f806fe92 | 65 | c = getc(stdin); |
Ivop | 1:7a82f806fe92 | 66 | |
Ivop | 1:7a82f806fe92 | 67 | printf("\n\rHello, world\n\r"); |
Ivop | 0:902f10e5d3e0 | 68 | } |