Skip to content

Instantly share code, notes, and snippets.

@kdpatino
Created October 9, 2017 16:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kdpatino/2ee31fd0dcd0a53a6d288b068c8c035e to your computer and use it in GitHub Desktop.
Psram Read
/*
* Copyright 2016 <Admobilize>
* MATRIX Labs [http://creator.matrix.one]
* This file is part of MATRIX Creator firmware for MCU
* Author: Andrés Calderón [andres.calderon@admobilize.com]
*
* MATRIX Creator firmware for MCU is free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ch.h"
#include "hal.h"
#include "board.h"
#include "chprintf.h"
#include <math.h>
#include <string.h>
#include <mcuconf.h>
#include "./i2c.h"
#include "./sensors_data.h"
#include "./mpl3115a2.h"
#include "./lsm9ds1.h"
#include "./hts221.h"
#include "./veml6070.h"
#include "./iCompass.h"
//Magnetic declination angle for iCompass
//Degrees for Miami Beach, FL (from http://www.magnetic-declination.com/)
#define MAG_DEC -6.683333
extern "C" {
#include "atmel_psram.h"
}
const uint32_t kFirmwareCreatorID = 0x10;
const uint32_t kFirmwareVersion = 0x170623; /* 0xYYMMDD */
/* Global objects */
creator::I2C i2c; // TODO(andres.calderon@admobilize.com): avoid global objects
void psram_copy(uint8_t mem_offset, char *data, uint8_t len) {
register char *psram = (char *)PSRAM_BASE_ADDRESS;
for (int i = 0; i < len; i++) {
psram[mem_offset + i] = data[i];
}
}
void psram_read(uint8_t mem_offset, char *data, uint8_t len) {
register char *psram = (char *)PSRAM_BASE_ADDRESS;
for (int i = 0; i < len; i++) {
data[i] = psram[mem_offset + i];
}
}
static WORKING_AREA(waIMUThread, 512);
static msg_t IMUThread(void *arg) {
(void)arg;
palSetPad(IOPORT3, 17);
chThdSleepMilliseconds(500);
palClearPad(IOPORT3, 17);
chprintf((BaseChannel *)&SD1, "Imu thread\n\r");
while (true) {
palSetPad(IOPORT3, 17);
chThdSleepMilliseconds(1);
palClearPad(IOPORT3, 17);
char data_test[10];
memset(data_test,0,sizeof(data_test));
psram_read(mem_offset_imu, (char *)&data_test, sizeof(data_test));
chThdSleepMilliseconds(400);
for (uint32_t i = 0; i < sizeof(data_test); ++i){
chprintf((BaseChannel *)&SD1, "Read Data from PI[%d]:%d\n\r",i,data_test[i]);
}
chprintf((BaseChannel *)&SD1, "\n\r");
}
return (0);
}
/*
* Application entry point.
*/
int main(void) {
halInit();
chSysInit();
sdStart(&SD1, NULL); /* Activates the serial driver 1 */
chprintf((BaseChannel *)&SD1, "MCU Debug\n\r");
/* Configure EBI I/O for psram connection*/
PIO_Configure(pinPsram, PIO_LISTSIZE(pinPsram));
/* complete SMC configuration between PSRAM and SMC waveforms.*/
BOARD_ConfigurePSRAM(SMC);
/* Creates the imu thread. */
chThdCreateStatic(waIMUThread, sizeof(waIMUThread), NORMALPRIO, IMUThread,
NULL);
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment