Guest User

Main.c Chibios

a guest
Oct 29th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. /*
  2.     ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
  3.  
  4.     Licensed under the Apache License, Version 2.0 (the "License");
  5.     you may not use this file except in compliance with the License.
  6.     You may obtain a copy of the License at
  7.  
  8.         http://www.apache.org/licenses/LICENSE-2.0
  9.  
  10.     Unless required by applicable law or agreed to in writing, software
  11.     distributed under the License is distributed on an "AS IS" BASIS,
  12.     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.     See the License for the specific language governing permissions and
  14.     limitations under the License.
  15. */
  16.  
  17. #include "ch.h"
  18. #include "hal.h"
  19. #include "ff.h"
  20.  
  21. #include "chprintf.h"
  22. #include "shell.h"
  23.  
  24. // Some fast made debug and error macros
  25. #define debug(args ...) chprintf((BaseSequentialStream *)&SD1, args); chprintf((BaseSequentialStream *)&SD1, "\r\n")
  26. #define error(args ...) chThdSleepMilliseconds(100); debug(args); while(1)
  27.  
  28.  
  29. // Serial / UART config
  30. static SerialConfig uartCfg =
  31. {
  32.   115200, // bit rate
  33.   0,
  34.   0,
  35.   0
  36. };
  37.  
  38. int main(void)
  39. {
  40.   halInit();
  41.   chSysInit();
  42.  
  43.   // Start the serial connection
  44.   sdStart(&SD1, &uartCfg);
  45.  
  46.   // Clear the terminal screen
  47.   char clear_data [7] = {27, '[', '2', 'J', 27, '[', 'H'};
  48.   sdWrite(&SD1, (uint8_t *) clear_data, sizeof(clear_data));
  49.  
  50.  
  51.   // Make alot of new lines
  52.   chThdSleepMilliseconds(100);
  53.   debug("\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ");
  54.   chThdSleepMilliseconds(100);
  55.  
  56.  
  57.   // init the SDC connection
  58.   sdcStart(&SDCD1, NULL);
  59.   sdcConnect(&SDCD1);
  60.  
  61.  
  62.   // The variables to be used for the fat fs
  63.   FATFS FatFs;
  64.   FIL fp;
  65.  
  66.   // Mount the file system
  67.   if(f_mount(&FatFs, "", 0) != FR_OK)
  68.   {
  69.     error("Couldn't mount fatfs");
  70.   }
  71.   // Open the file
  72.   if(f_open(&fp, "test.txt", FA_READ) != FR_OK)
  73.   {
  74.     error("Couldnt open file!");
  75.   }
  76.  
  77.   // Variables to read the print the data on the terminal
  78.   char buf;
  79.   uint16_t i;
  80.   UINT read;
  81.  
  82.   // Read and print the first 800 chars of file
  83.   for(i = 0 ; i < 800 ; i++)
  84.   {
  85.     f_read(&fp, &buf, 1, &read);
  86.     debug("buf[%03i] = %c\t%02x\t%i", i, buf, buf, read);
  87.   }
  88.  
  89.   while(true)
  90.   {
  91.     chThdSleepMilliseconds(1000);
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment