Satellite Observers Workbench. NOT yet complete, just published for forum posters to \"cherry pick\" pieces of code as requiered as an example.

Dependencies:   mbed

Committer:
AjK
Date:
Mon Oct 11 10:34:55 2010 +0000
Revision:
0:0a841b89d614
Totally Alpha quality as this project isn\t completed. Just publishing it as it answers many questions asked in the forums

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:0a841b89d614 1 /****************************************************************************
AjK 0:0a841b89d614 2 * Copyright 2010 Andy Kirkham, Stellar Technologies Ltd
AjK 0:0a841b89d614 3 *
AjK 0:0a841b89d614 4 * This file is part of the Satellite Observers Workbench (SOWB).
AjK 0:0a841b89d614 5 *
AjK 0:0a841b89d614 6 * SOWB is free software: you can redistribute it and/or modify
AjK 0:0a841b89d614 7 * it under the terms of the GNU General Public License as published by
AjK 0:0a841b89d614 8 * the Free Software Foundation, either version 3 of the License, or
AjK 0:0a841b89d614 9 * (at your option) any later version.
AjK 0:0a841b89d614 10 *
AjK 0:0a841b89d614 11 * SOWB is distributed in the hope that it will be useful,
AjK 0:0a841b89d614 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
AjK 0:0a841b89d614 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
AjK 0:0a841b89d614 14 * GNU General Public License for more details.
AjK 0:0a841b89d614 15 *
AjK 0:0a841b89d614 16 * You should have received a copy of the GNU General Public License
AjK 0:0a841b89d614 17 * along with SOWB. If not, see <http://www.gnu.org/licenses/>.
AjK 0:0a841b89d614 18 *
AjK 0:0a841b89d614 19 * $Id: main.cpp 5 2010-07-12 20:51:11Z ajk $
AjK 0:0a841b89d614 20 *
AjK 0:0a841b89d614 21 ***************************************************************************/
AjK 0:0a841b89d614 22
AjK 0:0a841b89d614 23 #include "sowb.h"
AjK 0:0a841b89d614 24 #include "user.h"
AjK 0:0a841b89d614 25 #include "flash.h"
AjK 0:0a841b89d614 26 #include "ssp0.h"
AjK 0:0a841b89d614 27 #include "gpio.h"
AjK 0:0a841b89d614 28
AjK 0:0a841b89d614 29 char mac_addr[6];
AjK 0:0a841b89d614 30
AjK 0:0a841b89d614 31 /** _25AA02E48_mac_addr
AjK 0:0a841b89d614 32 *
AjK 0:0a841b89d614 33 * Get a copy of the MAC address with a null terminator.
AjK 0:0a841b89d614 34 *
AjK 0:0a841b89d614 35 * @param char *s a buffer, 7 bytes long, to hold the MAC+null
AjK 0:0a841b89d614 36 */
AjK 0:0a841b89d614 37 void _25AA02E48_mac_addr(char *s) {
AjK 0:0a841b89d614 38 memcpy(s, mac_addr, 6);
AjK 0:0a841b89d614 39 s[6] = '\0';
AjK 0:0a841b89d614 40 }
AjK 0:0a841b89d614 41
AjK 0:0a841b89d614 42 /** _25AA02E48_mac_addr_printable
AjK 0:0a841b89d614 43 *
AjK 0:0a841b89d614 44 * Create a string that represents the MAC addr as a
AjK 0:0a841b89d614 45 * printable ASCII string. The caller is responsible
AjK 0:0a841b89d614 46 * for allocating enough space in the buffer pointed
AjK 0:0a841b89d614 47 * to by s to hold the string.
AjK 0:0a841b89d614 48 *
AjK 0:0a841b89d614 49 * @param char *s a buffer, 18 bytes long, to hold the MAC
AjK 0:0a841b89d614 50 * @param char divider A character to divide the bytes or 0
AjK 0:0a841b89d614 51 */
AjK 0:0a841b89d614 52 void _25AA02E48_mac_addr_printable(char *s, char divider) {
AjK 0:0a841b89d614 53 if (divider != 0) {
AjK 0:0a841b89d614 54 sprintf(s, "%02X%c%02X%c%02X%c%02X%c%02X%c%02X",
AjK 0:0a841b89d614 55 mac_addr[0], divider, mac_addr[1], divider, mac_addr[2], divider,
AjK 0:0a841b89d614 56 mac_addr[3], divider, mac_addr[4], divider, mac_addr[5]);
AjK 0:0a841b89d614 57 }
AjK 0:0a841b89d614 58 else {
AjK 0:0a841b89d614 59 sprintf(s, "%02X%02X%02X%02X%02X%02X",
AjK 0:0a841b89d614 60 mac_addr[0], mac_addr[1], mac_addr[2],
AjK 0:0a841b89d614 61 mac_addr[3], mac_addr[4], mac_addr[5]);
AjK 0:0a841b89d614 62 }
AjK 0:0a841b89d614 63 }
AjK 0:0a841b89d614 64
AjK 0:0a841b89d614 65 /** _25AA02E48_init
AjK 0:0a841b89d614 66 */
AjK 0:0a841b89d614 67 void _25AA02E48_init(void) {
AjK 0:0a841b89d614 68
AjK 0:0a841b89d614 69 /* Assumes SSP0 is already _init() */
AjK 0:0a841b89d614 70
AjK 0:0a841b89d614 71 while(!SSP0_request()) WHILE_WAITING_DO_PROCESS_FUNCTIONS;
AjK 0:0a841b89d614 72
AjK 0:0a841b89d614 73 LPC_SSP0->CPSR = _25AA02E48_SSP_INIT_CPSR;
AjK 0:0a841b89d614 74 AA02E48_CS_ASSERT;
AjK 0:0a841b89d614 75 FLASH_SHORT_COMMAND(FLASH_READ);
AjK 0:0a841b89d614 76 SSP0_WRITE_BYTE(0xFA);
AjK 0:0a841b89d614 77 SSP0_FLUSH_RX_FIFO;
AjK 0:0a841b89d614 78
AjK 0:0a841b89d614 79 for (int i = 0; i < 6; i++) {
AjK 0:0a841b89d614 80 SSP0_WRITE_BYTE(0x00);
AjK 0:0a841b89d614 81 while(SSP0_IS_BUSY || (LPC_SSP0->SR & (1UL << 2)) == 0);
AjK 0:0a841b89d614 82 mac_addr[i] = (char)LPC_SSP0->DR;
AjK 0:0a841b89d614 83 }
AjK 0:0a841b89d614 84
AjK 0:0a841b89d614 85 AA02E48_CS_DEASSERT;
AjK 0:0a841b89d614 86 LPC_SSP0->CPSR = FLASH_SSP_INIT_CPSR;
AjK 0:0a841b89d614 87 SSP0_release();
AjK 0:0a841b89d614 88 }