Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of d7a_1x by
src/d7a.cpp
- Committer:
- Jeej
- Date:
- 2016-09-01
- Revision:
- 45:b85384e7d825
- Parent:
- 43:28202405094d
- Child:
- 46:665391110051
File content as of revision 45:b85384e7d825:
#include "mbed.h"
#include "rtos.h"
#include "dbg.h"
#include "d7a.h"
#include "d7a_com.h"
#include "d7a_common.h"
#include "d7a_fs.h"
#include "d7a_modem.h"
#include "d7a_sys.h"
#include "d7a_alp.h"
//======================================================================
// d7a_open
//----------------------------------------------------------------------
/// @brief Open D7A driver and start the modem
/// @param d7a_com_config_t* Com port configuration structure
/// @param PinName Reset pin
/// @param d7a_fs_callbacks_t* File system callbacks (You declare files if this is not specified)
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_open(const d7a_com_config_t* com_config, PinName reset_pin, const d7a_fs_callbacks_t* fs_callbacks)
{
FPRINT("\r\n");
d7a_com_open(com_config);
d7a_sys_open();
d7a_fs_open(fs_callbacks);
d7a_alp_open();
d7a_modem_open(reset_pin);
return D7A_ERR_NONE;
}
//======================================================================
// d7a_close
//----------------------------------------------------------------------
/// @brief Close D7A driver and stop the modem
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_close(void)
{
FPRINT("\r\n");
// TODO
//d7a_modem_close();
//d7a_fs_close();
//d7a_sys_close();
d7a_com_close();
return D7A_ERR_NONE;
}
//======================================================================
// d7a_start
//----------------------------------------------------------------------
/// @brief Start the modem
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_start(void)
{
FPRINT("\r\n");
d7a_modem_start();
return D7A_ERR_NONE;
}
//======================================================================
// d7a_stop
//----------------------------------------------------------------------
/// @brief Stop the modem (goes to low power)
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_stop(void)
{
FPRINT("\r\n");
d7a_modem_stop();
return D7A_ERR_NONE;
}
//======================================================================
// d7a_create
//----------------------------------------------------------------------
/// @brief Creates a file on the modem
/// @param d7a_fs_storage_t Type of file
/// @param d7a_fs_perm_t Access permissions
/// @param uint32_t Length of the created file
/// @param uint32_t Maximum size of the file
/// @param uint8_t File ID to an eventual Action file
/// @param uint8_t File ID to an eventual Interface file
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_create(const uint8_t file_id, d7a_fs_storage_t prop, d7a_fs_perm_t perm, uint32_t size, uint32_t alloc, uint8_t action_file, uint8_t interface)
{
FPRINT("\r\n");
d7a_errors_t err;
DPRINT("Create %d.\r\n", file_id);
register_file_param_t file_infos = {
.fid = file_id,
.type = RAM,
.afid = action_file,
.ifid = interface,
.prop = (uint8_t)prop | ((interface)? FS_ACT_EN : 0),
.perm = (uint8_t)perm,
.size = size,
.alloc = alloc,
};
err = d7a_modem_register(&file_infos);
DPRINT("Create %d Done. err %d\r\n", file_id, err);
return err;
}
//======================================================================
// d7a_declare
//----------------------------------------------------------------------
/// @brief Declare a file stocked on the host to the modem (need to have implemented the fs_callbacks)
/// @param uint8_t File ID of file to declare
/// @param d7a_fs_storage_t Type of file
/// @param d7a_fs_perm_t Access permissions
/// @param uint32_t Length of the created file
/// @param uint32_t Maximum size of the file
/// @param uint8_t File ID to an eventual Action file
/// @param uint8_t File ID to an eventual Interface file
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_declare(const uint8_t file_id, d7a_fs_storage_t prop, d7a_fs_perm_t perm, uint32_t length, uint32_t alloc, uint8_t action_file, uint8_t interface)
{
FPRINT("\r\n");
DPRINT("Declare %d.\r\n", file_id);
register_file_param_t file_infos = {
.fid = file_id,
.type = HOST+RAM,
.afid = action_file,
.ifid = interface,
.prop = (uint8_t)prop | ((interface)? FS_ACT_EN : 0),
.perm = (uint8_t)perm,
.size = length,
.alloc = alloc,
};
d7a_modem_register(&file_infos);
DPRINT("Declare %d Done\r\n", file_id);
return D7A_ERR_NONE;
}
//======================================================================
// d7a_read
//----------------------------------------------------------------------
/// @brief Read data from a file
/// @param uint8_t File ID of file to read
/// @param uint32_t Offset from which to start reading
/// @param uint32_t Size of data to read
/// @param uint8_t* Buffer to retrieve data
/// @param uint8_t Retry policy
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_read(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* buf, d7a_addressee_t* addressee, uint8_t retry)
{
FPRINT("\r\n");
d7a_alp_read_file(file_id, offset, size, buf, addressee, retry);
return D7A_ERR_NONE;
}
//======================================================================
// d7a_write
//----------------------------------------------------------------------
/// @brief Write data to a file
/// @param uint8_t File ID of file to write
/// @param uint32_t Offset from which to start writing
/// @param uint32_t Size of data to write
/// @param uint8_t* Buffer of the data to write
/// @return d7a_errors_t Error code
//======================================================================
d7a_errors_t d7a_write(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* const buf, d7a_addressee_t* addressee, uint8_t retry, bool resp)
{
FPRINT("\r\n");
d7a_alp_write_file(file_id, offset, size, buf, addressee, retry, resp);
return D7A_ERR_NONE;
}
