Mbed port of RMCIOS. www.rmcios.fi https://github.com/fkorhone/

Dependencies:   mbed mbed-rtos EthernetInterface

Committer:
ransu
Date:
Thu Dec 27 19:21:42 2018 +0000
Revision:
0:aeaa6d2120a3
Initial commit to public.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ransu 0:aeaa6d2120a3 1 /*
ransu 0:aeaa6d2120a3 2 RMCIOS - Reactive Multipurpose Control Input Output System
ransu 0:aeaa6d2120a3 3 Copyright (c) 2018 Frans Korhonen
ransu 0:aeaa6d2120a3 4
ransu 0:aeaa6d2120a3 5 RMCIOS was originally developed at Institute for Atmospheric
ransu 0:aeaa6d2120a3 6 and Earth System Research / Physics, Faculty of Science,
ransu 0:aeaa6d2120a3 7 University of Helsinki, Finland
ransu 0:aeaa6d2120a3 8
ransu 0:aeaa6d2120a3 9 Assistance, experience and feedback from following persons have been
ransu 0:aeaa6d2120a3 10 critical for development of RMCIOS: Erkki Siivola, Juha Kangasluoma,
ransu 0:aeaa6d2120a3 11 Lauri Ahonen, Ella Häkkinen, Pasi Aalto, Joonas Enroth, Runlong Cai,
ransu 0:aeaa6d2120a3 12 Markku Kulmala and Tuukka Petäjä.
ransu 0:aeaa6d2120a3 13
ransu 0:aeaa6d2120a3 14 This file is part of RMCIOS. This notice was encoded using utf-8.
ransu 0:aeaa6d2120a3 15
ransu 0:aeaa6d2120a3 16 RMCIOS is free software: you can redistribute it and/or modify
ransu 0:aeaa6d2120a3 17 it under the terms of the GNU General Public License as published by
ransu 0:aeaa6d2120a3 18 the Free Software Foundation, either version 3 of the License, or
ransu 0:aeaa6d2120a3 19 (at your option) any later version.
ransu 0:aeaa6d2120a3 20
ransu 0:aeaa6d2120a3 21 RMCIOS is distributed in the hope that it will be useful,
ransu 0:aeaa6d2120a3 22 but WITHOUT ANY WARRANTY; without even the implied warranty of
ransu 0:aeaa6d2120a3 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ransu 0:aeaa6d2120a3 24 GNU General Public License for more details.
ransu 0:aeaa6d2120a3 25
ransu 0:aeaa6d2120a3 26 You should have received a copy of the GNU General Public Licenses
ransu 0:aeaa6d2120a3 27 along with RMCIOS. If not, see <http://www.gnu.org/licenses/>.
ransu 0:aeaa6d2120a3 28 */
ransu 0:aeaa6d2120a3 29
ransu 0:aeaa6d2120a3 30 #include "RMCIOS-functions.h"
ransu 0:aeaa6d2120a3 31
ransu 0:aeaa6d2120a3 32 // Channel function for allocating and freeing memory
ransu 0:aeaa6d2120a3 33 void stdout_func (void *data,
ransu 0:aeaa6d2120a3 34 const struct context_rmcios *context, int id,
ransu 0:aeaa6d2120a3 35 enum function_rmcios function,
ransu 0:aeaa6d2120a3 36 enum type_rmcios paramtype,
ransu 0:aeaa6d2120a3 37 union param_rmcios returnv,
ransu 0:aeaa6d2120a3 38 int num_params, const union param_rmcios param)
ransu 0:aeaa6d2120a3 39 {
ransu 0:aeaa6d2120a3 40
ransu 0:aeaa6d2120a3 41 }
ransu 0:aeaa6d2120a3 42
ransu 0:aeaa6d2120a3 43 // Channel function for allocating and freeing memory
ransu 0:aeaa6d2120a3 44 void mem_func (void *data,
ransu 0:aeaa6d2120a3 45 const struct context_rmcios *context, int id,
ransu 0:aeaa6d2120a3 46 enum function_rmcios function,
ransu 0:aeaa6d2120a3 47 enum type_rmcios paramtype,
ransu 0:aeaa6d2120a3 48 union param_rmcios returnv,
ransu 0:aeaa6d2120a3 49 int num_params, const union param_rmcios param)
ransu 0:aeaa6d2120a3 50 {
ransu 0:aeaa6d2120a3 51 switch (function)
ransu 0:aeaa6d2120a3 52 {
ransu 0:aeaa6d2120a3 53 case help_rmcios:
ransu 0:aeaa6d2120a3 54 // MEMORY INTERFACE:
ransu 0:aeaa6d2120a3 55 return_string (context, paramtype, returnv,
ransu 0:aeaa6d2120a3 56 " read mem \r\n "
ransu 0:aeaa6d2120a3 57 " -read ammount of free memory\r\n"
ransu 0:aeaa6d2120a3 58 " write mem \r\n "
ransu 0:aeaa6d2120a3 59 " -read memory allocation block size\r\n"
ransu 0:aeaa6d2120a3 60 " write mem n_bytes \r\n "
ransu 0:aeaa6d2120a3 61 " -Allocate n bytes of memory\r\n"
ransu 0:aeaa6d2120a3 62 " -Returns address of the allocated memory\r\n"
ransu 0:aeaa6d2120a3 63 " -On n_bytes < 0 allocates complete allocation blocks\r\n"
ransu 0:aeaa6d2120a3 64 " -returns 0 length on failure\r\n"
ransu 0:aeaa6d2120a3 65 " write mem (empty) addr(buffer/id)\r\n"
ransu 0:aeaa6d2120a3 66 " -free memory pointed by addr in buffer\r\n"
ransu 0:aeaa6d2120a3 67 );
ransu 0:aeaa6d2120a3 68 break;
ransu 0:aeaa6d2120a3 69
ransu 0:aeaa6d2120a3 70 case write_rmcios:
ransu 0:aeaa6d2120a3 71 if (num_params == 0)
ransu 0:aeaa6d2120a3 72 {
ransu 0:aeaa6d2120a3 73 } // Read memory allocation block size
ransu 0:aeaa6d2120a3 74 if (num_params == 1) // Allocate n bytes of memory
ransu 0:aeaa6d2120a3 75 {
ransu 0:aeaa6d2120a3 76 void *ptr = malloc (param_to_integer (context, paramtype,
ransu 0:aeaa6d2120a3 77 (const union param_rmcios)
ransu 0:aeaa6d2120a3 78 param, 0));
ransu 0:aeaa6d2120a3 79 //printf("allocated %x\n",ptr) ;
ransu 0:aeaa6d2120a3 80 return_binary (context, paramtype, returnv, (char *) &ptr,
ransu 0:aeaa6d2120a3 81 sizeof (ptr));
ransu 0:aeaa6d2120a3 82 }
ransu 0:aeaa6d2120a3 83 if (num_params > 1)
ransu 0:aeaa6d2120a3 84 {
ransu 0:aeaa6d2120a3 85 } // Write data to memory by access id
ransu 0:aeaa6d2120a3 86 if (num_params > 2)
ransu 0:aeaa6d2120a3 87 {
ransu 0:aeaa6d2120a3 88 } // +max size in bytes
ransu 0:aeaa6d2120a3 89 if (num_params > 3)
ransu 0:aeaa6d2120a3 90 {
ransu 0:aeaa6d2120a3 91 } // +starting at offset
ransu 0:aeaa6d2120a3 92 if (num_params == 2) // Free
ransu 0:aeaa6d2120a3 93 {
ransu 0:aeaa6d2120a3 94 if (param_to_integer
ransu 0:aeaa6d2120a3 95 (context, paramtype, (const union param_rmcios) param, 0) == 0)
ransu 0:aeaa6d2120a3 96 {
ransu 0:aeaa6d2120a3 97 char *ptr = 0;
ransu 0:aeaa6d2120a3 98 param_to_binary (context, paramtype, param, 1,
ransu 0:aeaa6d2120a3 99 sizeof (ptr), (char *) &ptr);
ransu 0:aeaa6d2120a3 100 //printf("freeing: %x\n",ptr) ;
ransu 0:aeaa6d2120a3 101 if (ptr != 0)
ransu 0:aeaa6d2120a3 102 free (ptr);
ransu 0:aeaa6d2120a3 103 }
ransu 0:aeaa6d2120a3 104 }
ransu 0:aeaa6d2120a3 105 break;
ransu 0:aeaa6d2120a3 106 }
ransu 0:aeaa6d2120a3 107 }
ransu 0:aeaa6d2120a3 108
ransu 0:aeaa6d2120a3 109