|
7 | 7 |
|
8 | 8 | Software License Agreement (BSD License) |
9 | 9 |
|
10 | | - Copyright (c) 2010, microBuilder SARL |
| 10 | + Copyright (c) 2011, microBuilder SARL |
11 | 11 | All rights reserved. |
12 | 12 |
|
13 | 13 | Redistribution and use in source and binary forms, with or without |
|
33 | 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
34 | 34 | */ |
35 | 35 | /**************************************************************************/ |
| 36 | +#include <stdlib.h> |
36 | 37 | #include <stdio.h> |
| 38 | +#include <string.h> |
37 | 39 |
|
38 | 40 | #include "projectconfig.h" |
39 | 41 | #include "sysinit.h" |
40 | 42 |
|
41 | | -#include "drivers/sensors/pn532/pn532.h" |
42 | | -#include "drivers/sensors/pn532/pn532_drvr.h" |
| 43 | +#include "core/gpio/gpio.h" |
| 44 | +#include "core/systick/systick.h" |
| 45 | + |
| 46 | +#ifdef CFG_INTERFACE |
| 47 | + #include "core/cmd/cmd.h" |
| 48 | +#endif |
43 | 49 |
|
44 | 50 | /**************************************************************************/ |
45 | 51 | /*! |
46 | | - Main program entry point. After reset, normal code execution will |
47 | | - begin here. |
| 52 | + Approximates a 1 millisecond delay using "nop". This is less |
| 53 | + accurate than a dedicated timer, but is useful in certain situations. |
48 | 54 |
|
49 | | - Note: CFG_INTERFACE is normally enabled by default. If you wish to |
50 | | - enable the blinking LED code in main, you will need to open |
51 | | - projectconfig.h, comment out "#define CFG_INTERFACE" and |
52 | | - rebuild the project. |
| 55 | + The number of ticks to delay depends on the optimisation level set |
| 56 | + when compiling (-O). Depending on the compiler settings, one of the |
| 57 | + two defined values for 'delay' should be used. |
53 | 58 | */ |
54 | 59 | /**************************************************************************/ |
55 | | -int main (void) |
| 60 | +void delayms(uint32_t ms) |
56 | 61 | { |
57 | | - #ifdef CFG_INTERFACE |
58 | | - //#error "CFG_INTERFACE must be disabled in projectconfig.h for this demo" |
59 | | - #endif |
60 | | - #if !defined CFG_PRINTF_USBCDC |
61 | | - #error "CFG_PRINTF_USBCDC must be enabled in projectconfig.h for this demo" |
62 | | - #endif |
| 62 | + uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 45); // Release Mode (-Os) |
| 63 | + // uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 120); // Debug Mode (No optimisations) |
| 64 | + |
| 65 | + while (delay > 0) |
| 66 | + { |
| 67 | + __asm volatile ("nop"); |
| 68 | + delay--; |
| 69 | + } |
| 70 | +} |
63 | 71 |
|
| 72 | +/**************************************************************************/ |
| 73 | +/*! |
| 74 | + Main program entry point. After reset, normal code execution will |
| 75 | + begin here. |
| 76 | +*/ |
| 77 | +/**************************************************************************/ |
| 78 | +int main(void) |
| 79 | +{ |
64 | 80 | // Configure cpu and mandatory peripherals |
65 | 81 | systemInit(); |
66 | | - |
67 | | - // Wait 5 second for someone to open the USB connection for printf |
68 | | - systickDelay(5000); |
69 | | - |
70 | | - // Initialise the PN532 |
71 | | - pn532Init(); |
72 | 82 |
|
73 | | - byte_t response[256]; |
74 | | - size_t responseLen; |
75 | | - pn532_error_t error; |
76 | | - |
77 | | - // Setup command to initialise a single ISO14443A target at 106kbps |
78 | | - byte_t abtCommand[] = { PN532_COMMAND_INLISTPASSIVETARGET, 0x01, PN532_MODULATION_ISO14443A_106KBPS }; |
| 83 | + uint32_t currentSecond, lastSecond; |
| 84 | + currentSecond = lastSecond = 0; |
79 | 85 |
|
80 | 86 | while (1) |
81 | 87 | { |
82 | | - printf("%s", CFG_PRINTF_NEWLINE); |
83 | | - printf("Wait for an ISO14443A card (Mifare Classic, etc.)%s", CFG_PRINTF_NEWLINE); |
84 | | - |
85 | | - // Send the command |
86 | | - error = pn532Write(abtCommand, sizeof(abtCommand)); |
87 | | - |
88 | | - // Wait until we get a response or an unexpected error message |
89 | | - do |
90 | | - { |
91 | | - error = pn532Read(response, &responseLen); |
92 | | - systickDelay(25); |
93 | | - } |
94 | | - #ifdef PN532_UART |
95 | | - while (error == PN532_ERROR_RESPONSEBUFFEREMPTY); |
96 | | - #endif |
97 | | - #ifdef PN532_SPI |
98 | | - while ((error == PN532_ERROR_RESPONSEBUFFEREMPTY) || (error = PN532_ERROR_SPIREADYSTATUSTIMEOUT)); |
99 | | - #endif |
100 | | - |
101 | | - // Print the card details if possible |
102 | | - if (!error) |
| 88 | + // Toggle LED once per second ... rollover = 136 years :) |
| 89 | + currentSecond = systickGetSecondsActive(); |
| 90 | + if (currentSecond != lastSecond) |
103 | 91 | { |
104 | | - /* Response for ISO14443A 106KBPS (Mifare Classic, etc.) |
105 | | - See UM0701-02 section 7.3.5 for more information |
106 | | -
|
107 | | - byte Description |
108 | | - ------------- ------------------------------------------ |
109 | | - b7 Tags Found |
110 | | - b8 Tag Number (only one used in this example) |
111 | | - b9..10 SENS_RES |
112 | | - b11 SEL_RES |
113 | | - b12 NFCID Length |
114 | | - b13..NFCIDLen NFCID |
115 | | - |
116 | | - SENS_RES SEL_RES Manufacturer/Card Type NFCID Len |
117 | | - -------- ------- ----------------------- --------- |
118 | | - 00 04 08 NXP Mifare Classic 1K 4 bytes */ |
119 | | - |
120 | | - printf("%s", CFG_PRINTF_NEWLINE); |
121 | | - printf("%-12s: %d %s", "Tags Found", response[7], CFG_PRINTF_NEWLINE); |
122 | | - printf("%-12s: %02X %02X %s", "SENS_RES", response[9], response[10], CFG_PRINTF_NEWLINE); |
123 | | - printf("%-12s: %02X %s", "SEL_RES", response[11], CFG_PRINTF_NEWLINE); |
124 | | - printf("%-12s: ", "NFCID"); |
125 | | - size_t pos; |
126 | | - for (pos=0; pos < response[12]; pos++) |
| 92 | + lastSecond = currentSecond; |
| 93 | + if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF) |
127 | 94 | { |
128 | | - printf("%02x ", response[13 + pos]); |
| 95 | + gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); |
129 | 100 | } |
130 | | - printf(CFG_PRINTF_NEWLINE); |
131 | | - } |
132 | | - else |
133 | | - { |
134 | | - // Oops .... something bad happened. Check 'error' |
135 | | - printf("Ooops! Error %02X %s", error, CFG_PRINTF_NEWLINE); |
136 | 101 | } |
137 | 102 |
|
138 | | - // Wait at least one second before trying again |
139 | | - systickDelay(1000); |
| 103 | + // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h |
| 104 | + #ifdef CFG_INTERFACE |
| 105 | + cmdPoll(); |
| 106 | + #endif |
140 | 107 | } |
| 108 | + |
| 109 | + return 0; |
141 | 110 | } |
0 commit comments