Morpheus / target-mcu-k64f

Fork of target-mcu-k64f by -deleted-

Committer:
screamer
Date:
Wed Mar 23 21:24:48 2016 +0000
Revision:
0:c5e2f793b59a
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:c5e2f793b59a 1 /* mbed Microcontroller Library
screamer 0:c5e2f793b59a 2 * Copyright (c) 2006-2013 ARM Limited
screamer 0:c5e2f793b59a 3 *
screamer 0:c5e2f793b59a 4 * Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:c5e2f793b59a 5 * you may not use this file except in compliance with the License.
screamer 0:c5e2f793b59a 6 * You may obtain a copy of the License at
screamer 0:c5e2f793b59a 7 *
screamer 0:c5e2f793b59a 8 * http://www.apache.org/licenses/LICENSE-2.0
screamer 0:c5e2f793b59a 9 *
screamer 0:c5e2f793b59a 10 * Unless required by applicable law or agreed to in writing, software
screamer 0:c5e2f793b59a 11 * distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:c5e2f793b59a 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:c5e2f793b59a 13 * See the License for the specific language governing permissions and
screamer 0:c5e2f793b59a 14 * limitations under the License.
screamer 0:c5e2f793b59a 15 */
screamer 0:c5e2f793b59a 16 #include "gpio_api.h"
screamer 0:c5e2f793b59a 17
screamer 0:c5e2f793b59a 18 #define CRC16
screamer 0:c5e2f793b59a 19 #include "crc.h"
screamer 0:c5e2f793b59a 20
screamer 0:c5e2f793b59a 21 // called before main - implement here if board needs it ortherwise, let
screamer 0:c5e2f793b59a 22 // the application override this if necessary
screamer 0:c5e2f793b59a 23 //void mbed_sdk_init()
screamer 0:c5e2f793b59a 24 //{
screamer 0:c5e2f793b59a 25 //
screamer 0:c5e2f793b59a 26 //}
screamer 0:c5e2f793b59a 27
screamer 0:c5e2f793b59a 28 // Change the NMI pin to an input. This allows NMI pin to
screamer 0:c5e2f793b59a 29 // be used as a low power mode wakeup. The application will
screamer 0:c5e2f793b59a 30 // need to change the pin back to NMI_b or wakeup only occurs once!
screamer 0:c5e2f793b59a 31 void NMI_Handler(void)
screamer 0:c5e2f793b59a 32 {
screamer 0:c5e2f793b59a 33 gpio_t gpio;
screamer 0:c5e2f793b59a 34 gpio_init_in(&gpio, PTA4);
screamer 0:c5e2f793b59a 35 }
screamer 0:c5e2f793b59a 36
screamer 0:c5e2f793b59a 37 // Provide ethernet devices with a semi-unique MAC address from the UUID
screamer 0:c5e2f793b59a 38 void mbed_mac_address(char *mac)
screamer 0:c5e2f793b59a 39 {
screamer 0:c5e2f793b59a 40
screamer 0:c5e2f793b59a 41 unsigned int UUID_LOC_BASE = 0x40048054; // First adddress of the 4-word UUID
screamer 0:c5e2f793b59a 42 char uuid[16]; // So we can take a local copy of the UUID
screamer 0:c5e2f793b59a 43 uint32_t MAC[3]; // 3 16 bits words for the MAC
screamer 0:c5e2f793b59a 44
screamer 0:c5e2f793b59a 45 // copy the UUID to the variable MAC[]
screamer 0:c5e2f793b59a 46 memcpy(uuid,(const void*)UUID_LOC_BASE,sizeof(uuid));
screamer 0:c5e2f793b59a 47
screamer 0:c5e2f793b59a 48 // generate three CRC16's using different slices of the UUID
screamer 0:c5e2f793b59a 49 MAC[0] = crcSlow(uuid, 8); // most significant half-word
screamer 0:c5e2f793b59a 50 MAC[1] = crcSlow(uuid, 12);
screamer 0:c5e2f793b59a 51 MAC[2] = crcSlow(uuid, 16); // least significant half word
screamer 0:c5e2f793b59a 52
screamer 0:c5e2f793b59a 53 // The network stack expects an array of 6 bytes
screamer 0:c5e2f793b59a 54 // so we copy, and shift and copy from the half-word array to the byte array
screamer 0:c5e2f793b59a 55 mac[0] = MAC[0] >> 8;
screamer 0:c5e2f793b59a 56 mac[1] = MAC[0];
screamer 0:c5e2f793b59a 57 mac[2] = MAC[1] >> 8;
screamer 0:c5e2f793b59a 58 mac[3] = MAC[1];
screamer 0:c5e2f793b59a 59 mac[4] = MAC[2] >> 8;
screamer 0:c5e2f793b59a 60 mac[5] = MAC[2];
screamer 0:c5e2f793b59a 61
screamer 0:c5e2f793b59a 62 // We want to force bits [1:0] of the most significant byte [0]
screamer 0:c5e2f793b59a 63 // to be "10"
screamer 0:c5e2f793b59a 64 // http://en.wikipedia.org/wiki/MAC_address
screamer 0:c5e2f793b59a 65
screamer 0:c5e2f793b59a 66 mac[0] |= 0x02; // force bit 1 to a "1" = "Locally Administered"
screamer 0:c5e2f793b59a 67 mac[0] &= 0xFE; // force bit 0 to a "0" = Unicast
screamer 0:c5e2f793b59a 68
screamer 0:c5e2f793b59a 69 }
screamer 0:c5e2f793b59a 70
screamer 0:c5e2f793b59a 71
screamer 0:c5e2f793b59a 72