Frans Korhonen / Mbed 2 deprecated RMCIOS-Mbed

Dependencies:   mbed mbed-rtos EthernetInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers context.c Source File

context.c

00001 /* 
00002 RMCIOS - Reactive Multipurpose Control Input Output System
00003 Copyright (c) 2018 Frans Korhonen
00004 
00005 RMCIOS was originally developed at Institute for Atmospheric 
00006 and Earth System Research / Physics, Faculty of Science, 
00007 University of Helsinki, Finland
00008 
00009 Assistance, experience and feedback from following persons have been 
00010 critical for development of RMCIOS: Erkki Siivola, Juha Kangasluoma, 
00011 Lauri Ahonen, Ella Häkkinen, Pasi Aalto, Joonas Enroth, Runlong Cai, 
00012 Markku Kulmala and Tuukka Petäjä.
00013 
00014 This file is part of RMCIOS. This notice was encoded using utf-8.
00015 
00016 RMCIOS is free software: you can redistribute it and/or modify
00017 it under the terms of the GNU General Public License as published by
00018 the Free Software Foundation, either version 3 of the License, or
00019 (at your option) any later version.
00020 
00021 RMCIOS is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public Licenses
00027 along with RMCIOS.  If not, see <http://www.gnu.org/licenses/>.
00028 */
00029 
00030 #include "RMCIOS-functions.h"
00031 
00032 // Channel function for allocating and freeing memory
00033 void stdout_func (void *data,
00034                const struct context_rmcios *context, int id,
00035                enum function_rmcios function,
00036                enum type_rmcios paramtype,
00037                union param_rmcios returnv,
00038                int num_params, const union param_rmcios param)
00039 {
00040     
00041 }
00042 
00043 // Channel function for allocating and freeing memory
00044 void mem_func (void *data,
00045                const struct context_rmcios *context, int id,
00046                enum function_rmcios function,
00047                enum type_rmcios paramtype,
00048                union param_rmcios returnv,
00049                int num_params, const union param_rmcios param)
00050 {
00051    switch (function)
00052    {
00053    case help_rmcios:
00054       // MEMORY INTERFACE: 
00055       return_string (context, paramtype, returnv,
00056                      " read mem \r\n "
00057                      "   -read ammount of free memory\r\n"
00058                      " write mem \r\n "
00059                      "   -read memory allocation block size\r\n"
00060                      " write mem n_bytes \r\n "
00061                      "   -Allocate n bytes of memory\r\n"
00062                      "   -Returns address of the allocated memory\r\n"
00063                      "   -On n_bytes < 0 allocates complete allocation blocks\r\n"
00064                      "   -returns 0 length on failure\r\n"
00065                      " write mem (empty) addr(buffer/id)\r\n"
00066                      "   -free memory pointed by addr in buffer\r\n"
00067                      );
00068       break;
00069 
00070    case write_rmcios:
00071       if (num_params == 0)
00072       {
00073       } // Read memory allocation block size
00074       if (num_params == 1)      // Allocate n bytes of memory
00075       {
00076          void *ptr = malloc (param_to_integer (context, paramtype,
00077                                                (const union param_rmcios)
00078                                                param, 0));
00079          //printf("allocated %x\n",ptr) ;
00080          return_binary (context, paramtype, returnv, (char *) &ptr,
00081                         sizeof (ptr));
00082       }
00083       if (num_params > 1)
00084       {
00085       } // Write data to memory by access id
00086       if (num_params > 2)
00087       {
00088       } // +max size in bytes
00089       if (num_params > 3)
00090       {
00091       } // +starting at offset
00092       if (num_params == 2)      // Free 
00093       {
00094          if (param_to_integer
00095              (context, paramtype, (const union param_rmcios) param, 0) == 0)
00096          {
00097             char *ptr = 0;
00098             param_to_binary (context, paramtype, param, 1,
00099                              sizeof (ptr), (char *) &ptr);
00100             //printf("freeing: %x\n",ptr) ;
00101             if (ptr != 0)
00102                free (ptr);
00103          }
00104       }
00105       break;
00106    }
00107 }
00108 
00109